How to search a string over multiple fields in ES

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"
}
}
}
}

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?

hi Thanks for reply ,here is my mapping.

{
    "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"
        ]
    }
}

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).

1 Like

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