0

I'm using the bool query for the 'must' and 'must_not' feature. It works as expected until I get to a property that is 3 levels deep. for example a simple match query such as ...

GET city/town/_search
{
    "query": {
        "match": {
            "contact.residence.address": "Rocky Road"
        }
    }

}

works just fine and returns the results but if I do the same in a bool query like ..

GET city/town/_search
{
   "query": {
      "bool": {
         "must": [
            {
               "term": {
                  "contact.residence.address": "Rocky Road"
               }
            }
         ]
      }
   }
}

return NO Results. Why is this????? Keep in mind other bool queries such as ..

GET city/town/_search
{
   "query": {
      "bool": {
         "must": [
            {
               "term": {
                  "store.name": "Hendersons"
               }
            }
         ]
      }
   }
}

work just fine! Its only for any field that is 3 level deep, hence searching any term that is prop1.prop3.prop3

1
  • You might have contact.residence.address field mapped with text type. If it is the case then by replacing term with match in your second query will work as expected. I would suggest you to read the section Why doesn’t the term query match my document? in official docs here. Commented Apr 4, 2017 at 20:16

1 Answer 1

2

The reason is that the first search uses match query whereas another one uses term query. The difference is that match query applies analyzer to the input which gives correct terms. term query doesn't analyze your input and uses it as a single term. It might give the same result for inputs like "Hendersons" but for input "Rocky Road" it must be splitted into two terms, so you must use match query

GET city/town/_search
{
   "query": {
      "bool": {
         "must": [
            {
               "match": {
                  "contact.residence.address": "Rocky Road"
               }
            }
         ]
      }
   }
}
Sign up to request clarification or add additional context in comments.

1 Comment

Worked like a charm. Thank you!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.