# How to search a string over multiple fields in ES

**URL:** <https://discuss.elastic.co/t/how-to-search-a-string-over-multiple-fields-in-es/64237>\
**Category:** Elasticsearch\
**Created:** [October 28, 2016, 4:48am UTC](https://discuss.elastic.co/t/how-to-search-a-string-over-multiple-fields-in-es/64237 "2016-10-28T04:48:39Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![prasad\_kp](https://avatars.discourse-cdn.com/v4/letter/p/dc4da7/32.png) [@prasad\_kp](https://discuss.elastic.co/u/prasad_kp)\
**Post date:** [October 28, 2016, 4:48am UTC](https://discuss.elastic.co/t/how-to-search-a-string-over-multiple-fields-in-es/64237/1 "2016-10-28T04:48:39Z")

</div>

I Have "oil" string taht need to be searched in specific fields .

I have the following query but its hits are 0 with this query,m i missing something in this query.

{  
"bool" : {  
"must" : {  
"query\_string" : {  
"query" : "oil OR lubricate OR lube",  
"fields" : ["BrandName", "Cat", "Desc", "LineCode", "PartNumber", "Term"],  
"default\_operator" : "and"  
}  
}  
}  
}

---

<div class="post-metadata">

**Author:** ![cbuescher](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/cbuescher/32/60402_2.png) [@cbuescher](https://discuss.elastic.co/u/cbuescher)\
**Post date:** [October 28, 2016, 8:31am UTC](https://discuss.elastic.co/t/how-to-search-a-string-over-multiple-fields-in-es/64237/2 "2016-10-28T08:31:35Z")

</div>

Hi,

Works for me with a smaller example, maybe you have misconfigured the mapping for the field the string appears in. Can you check the mapping and maybe come back with a recreation that involves one or two documents?

---

<div class="post-metadata">

**Author:** ![prasad\_kp](https://avatars.discourse-cdn.com/v4/letter/p/dc4da7/32.png) [@prasad\_kp](https://discuss.elastic.co/u/prasad_kp)\
**Post date:** [October 28, 2016, 8:34am UTC](https://discuss.elastic.co/t/how-to-search-a-string-over-multiple-fields-in-es/64237/3 "2016-10-28T08:34:37Z")

</div>

hi Thanks for reply ,here is my mapping.

```auto
{
    "BrandName": {
        "type": "string",
        "index": "not_analyzed",
        "fields": {
            "raw": {
                "type": "string"
            }
        },
        "copy_to": [
            "did_you_mean"
        ]
    },
    "Cat": {
        "type": "string",
        "index": "not_analyzed",
        "fields": {
            "raw": {
                "type": "string"
            }
        },
        "copy_to": [
            "did_you_mean"
        ]
    },
    "Term": {
        "type": "string",
        "index": "not_analyzed",
        "fields": {
            "raw": {
                "type": "string"
            }
        },
        "copy_to": [
            "did_you_mean"
        ]
    }
}

```

---

<div class="post-metadata">

**Author:** ![cbuescher](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/cbuescher/32/60402_2.png) [@cbuescher](https://discuss.elastic.co/u/cbuescher)\
**Post date:** [October 28, 2016, 5:20pm UTC](https://discuss.elastic.co/t/how-to-search-a-string-over-multiple-fields-in-es/64237/4 "2016-10-28T17:20:10Z")

</div>

> [@prasad\_kp](#):
>
> ```auto
> "BrandName": {
> "type": "string",
> "index": "not_analyzed",
> "fields": {
> "raw": {
> "type": "string"
> }
> },
> "copy_to": [
> "did_you_mean"
> ]
> }
> 
> ```

Your mapping shows that your fields are `not_analyzed`, so unless any field in your docs _exactly_ matches one of the query terms you won't get any result. The `raw` subfields however seem to be analyzed, so if you e.g. use `BrandName.raw` in your query above (also for the other fields that have a `raw` subfield) this should work. Normally, however, people do it the other way round in their mappings: analyze the main field an have a non-analyzed version in the `raw` field for exact phrase matches (if you need them).

---

<div class="post-metadata">

**Author:** ![prasad\_kp](https://avatars.discourse-cdn.com/v4/letter/p/dc4da7/32.png) [@prasad\_kp](https://discuss.elastic.co/u/prasad_kp)\
**Post date:** [November 2, 2016, 5:56pm UTC](https://discuss.elastic.co/t/how-to-search-a-string-over-multiple-fields-in-es/64237/5 "2016-11-02T17:56:19Z")

</div>

Thanks Alot...!!!!!!! Christoph Büscher .raw worked for me

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 5, 2017, 10:07pm UTC](https://discuss.elastic.co/t/how-to-search-a-string-over-multiple-fields-in-es/64237/6 "2017-07-05T22:07:15Z")

</div>


