# Bool Query giving inappropriate results

**URL:** https://discuss.elastic.co/t/bool-query-giving-inappropriate-results/223277
**Category:** Elasticsearch
**Created:** [March 12, 2020, 8:16am UTC](https://discuss.elastic.co/t/bool-query-giving-inappropriate-results/223277 "2020-03-12T08:16:09Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![cravinder489](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/cravinder489/32/62858_2.png) [@cravinder489](https://discuss.elastic.co/u/cravinder489)
#### Post date: [March 12, 2020, 8:16am UTC](https://discuss.elastic.co/t/bool-query-giving-inappropriate-results/223277/1 "2020-03-12T08:16:09Z")

</div>

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?

---

<div class="post-metadata">

### Author: ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)
#### Post date: [March 12, 2020, 10:28am UTC](https://discuss.elastic.co/t/bool-query-giving-inappropriate-results/223277/2 "2020-03-12T10:28:03Z")

</div>

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!

---

<div class="post-metadata">

### Author: ![Mark\_Harwood](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mark_harwood/32/10538_2.png) [@Mark\_Harwood](https://discuss.elastic.co/u/Mark_Harwood)
#### Post date: [March 12, 2020, 10:46am UTC](https://discuss.elastic.co/t/bool-query-giving-inappropriate-results/223277/3 "2020-03-12T10:46:35Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![cravinder489](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/cravinder489/32/62858_2.png) [@cravinder489](https://discuss.elastic.co/u/cravinder489)
#### Post date: [March 12, 2020, 11:20am UTC](https://discuss.elastic.co/t/bool-query-giving-inappropriate-results/223277/4 "2020-03-12T11:20:28Z")

</div>

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

---

<div class="post-metadata">

### Author: ![cravinder489](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/cravinder489/32/62858_2.png) [@cravinder489](https://discuss.elastic.co/u/cravinder489)
#### Post date: [March 12, 2020, 11:22am UTC](https://discuss.elastic.co/t/bool-query-giving-inappropriate-results/223277/5 "2020-03-12T11:22:03Z")

</div>

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

---

<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: [April 9, 2020, 11:22am UTC](https://discuss.elastic.co/t/bool-query-giving-inappropriate-results/223277/6 "2020-04-09T11:22:13Z")

</div>

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