Bool Query giving inappropriate results

This is the structure of my index "chatbot" :

{
  "chatbot" : {
    "aliases" : { },
    "mappings" : {
      "properties" : {
        "answer" : {
          "type" : "text"
        },
        "creationDate" : {
          "type" : "date"
        },
        "isValid" : {
          "type" : "boolean"
        },
        "owner" : {
          "type" : "text"
        },
        "ques" : {
          "type" : "text"
        },
        "tags" : {
          "type" : "keyword"
        },
        "title" : {
          "type" : "text"
        }
      }
    },
    "settings" : {
      "index" : {
        "creation_date" : "1583998852641",
        "number_of_shards" : "3",
        "number_of_replicas" : "1",
        "uuid" : "xd5cQ4-qSjyjumhLBAPKcQ",
        "version" : {
          "created" : "7010199"
        },
        "provided_name" : "chatbot"
      }
    }
  }
}

I have data corresponding to different types of "owner". What I want to do is to search for some data in "ques" field. Also, I specify the "owner" field for getting the result from a particular owner.

For this I'm using bool query:

GET /chatbot/_search
{
"query": {
"bool": {
"must": [
{ "match": { "ques": "alternate sources" } }
],
"filter": { "term": { "owner": "Registration" } }
}
}
}

But I'm not getting any document in the result. In my data I have one document which satisfies this condition.

Why is this happening?

How do I search for different data in different fields in Elasticsearch?

Can you provide a full but minimal reproduction, including index creation, document indexing and the query you are using.

Also, please mention the Elasticsearch version you are trying this with. Thanks!

The term clause in your filter is not tokenized so is taken as an exact match with case sensitivity.
However, the owner field is a text type field which is tokenized and therefore likely to be lower cased. That's why they don't match.
Try use a match clause instead which performs appropriate tokenisation for a field or make "Registration" lower-case in the terms clause.

Thank You Mark
Your reply really helped. When i give value of "owner" as "registration" instead of "Registration", I'm getting desired output.
Also, now I replaced my term query by match query and there is no issue of uppercase or lowercase.
Thank You So Much

Thank You Alexander for replying to my query.
It was occurring because my term clause in the filter query was not tokenized.

1 Like

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.