# Boolean Query

**URL:** <https://discuss.elastic.co/t/boolean-query/25351>\
**Category:** Elasticsearch\
**Created:** [July 10, 2015, 8:04pm UTC](https://discuss.elastic.co/t/boolean-query/25351 "2015-07-10T20:04:13Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![travagini](https://avatars.discourse-cdn.com/v4/letter/t/9d8465/32.png) [@travagini](https://discuss.elastic.co/u/travagini)\
**Post date:** [July 10, 2015, 8:04pm UTC](https://discuss.elastic.co/t/boolean-query/25351/1 "2015-07-10T20:04:14Z")

</div>

I'm trying to query basically three AND's: "fields.name": "Date One" AND "fields.value": "2015-07-10" AND "filds.value\_full": "Jhon Benny"

Here's what I tryed before:

```
{
   "query": {
      "filtered": {
         "query": {
            "match_all": {}
         },
         "filter": {
            "nested": {
               "path": "fields",
               "filter": {
                  "bool": {
                     "must": [
                        {
                           "term": {
                              "fields.name": "Date One"
                           }
                        },
                        {
                           "term": {
                              "fields.value": "2015-07-10"
                           }
                        }
                     ],
                     "should": [
                       {
                         "term": {
                           "fields.value_full": "John Benny"
                         }
                       },
                       {
                         "term": {
                           "fields.value": "Client"
                         }
                       }
                     ]
                  }
               }
            }
         }
      }
   }
}

```

And my JSON is this one here:

```
{
   "id": 1,
   "collection": "Document",
   "data_cad": "2015-07-10",
   "type_document": "Contract",
   "confidencial": "false",
   "fields": [
       {
           "name": "Date One",
           "value": "2015-07-10"
       },
       {
           "name": "Date Two",
           "value": "2017-07-10"
       },
       {
           "name": "Client",
           "value_full": "Jhon Benny"
       },
       {
           "name": "Value of Contract",
           "value_contract": 520.50
       }
   ]
}

```

If I just leave "fields.name": "Date One" AND "fields.value": "2015-07-10" it works fine, but as I wrote here, I get no results back.

---

<div class="post-metadata">

**Author:** ![colings86](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/colings86/32/44960_2.png) [@colings86](https://discuss.elastic.co/u/colings86)\
**Post date:** [July 12, 2015, 9:57am UTC](https://discuss.elastic.co/t/boolean-query/25351/2 "2015-07-12T09:57:19Z")

</div>

The `field.value_full` is `Jhon Benny` in your document and `John Benny` in your query. This could be the reason?

If that doesn't fix it, could you paste your mappings for those fields here?

---

<div class="post-metadata">

**Author:** ![travagini](https://avatars.discourse-cdn.com/v4/letter/t/9d8465/32.png) [@travagini](https://discuss.elastic.co/u/travagini)\
**Post date:** [July 13, 2015, 1:16am UTC](https://discuss.elastic.co/t/boolean-query/25351/3 "2015-07-13T01:16:37Z")

</div>

Unfortunately it didn't fix the problem.

The mapping:

```
{
   
      "mappings": {
         "my_type": {
            "properties": {
               "fields": {
                  "type": "nested",
                  
                  "properties": {
                     "name": {
                        "type": "string"
                     },
                     "value": {
                        "type": "date",
                        "format": "dateOptionalTime"
                     },
                     "value_contract": {
                        "type": "double"
                     },
                     "value_full": {
                        "type": "string"
                     }
                  }
               },
               "collection": {
                  "type": "string"
               },
               "confidencial": {
                  "type": "string"
               },
               "data_cad": {
                  "type": "date",
                  "format": "dateOptionalTime"
               },
               "id": {
                  "type": "long"
               },
               "type_document": {
                  "type": "string"
               }
            }
         }
      }
   
}
```

---

<div class="post-metadata">

**Author:** ![colings86](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/colings86/32/44960_2.png) [@colings86](https://discuss.elastic.co/u/colings86)\
**Post date:** [July 13, 2015, 6:53am UTC](https://discuss.elastic.co/t/boolean-query/25351/4 "2015-07-13T06:53:21Z")

</div>

The reason you are getting no results is that your `value_full` field is analysed so `John Benny` will be split into two terms in the index `john` and `benny`. The [`term` filter](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-term-filter.html) does not apply the analyzer to your search string so you are still searching for `John Benny` as a term in the index which does not exist. You have a few options here:

1. Set `"index": "not_analyzed"` on the `value_full` field so you can do exact matching on it using the `term` filter. Note that you will not be able to do partial matching on `value_full` if you use this solution
2. Use a filter/query that applies the analyzer to your search string. [The `match` query](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-match-query.html) will do this but you will either need to add it to the `query` section of your `filtered_query` or wrap it in a [`query` filter](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-query-filter.html).
3. change your search terms to look for the actual terms rather than complete search string. This is the most brittle solution and the hardest to maintain since any changes to your analysis chain will affect the terms you need to search for.

---

<div class="post-metadata">

**Author:** ![travagini](https://avatars.discourse-cdn.com/v4/letter/t/9d8465/32.png) [@travagini](https://discuss.elastic.co/u/travagini)\
**Post date:** [July 14, 2015, 6:01pm UTC](https://discuss.elastic.co/t/boolean-query/25351/5 "2015-07-14T18:01:52Z")

</div>

Thank you for your helping! But I did what you said and put a "query" fillter before. However I got no results back.

```
{
   "query": {
      "filtered": {
         "query": {
            "match": {
              "fields.value_full": "Jhon"
            }
         },
         "filter": {
            "nested": {
               "path": "fields",
               "filter": {
                  "bool": {
                     "must": [
                        {
                           "term": {
                              "fields.name": "Date One"
                           }
                        },
                        {
                           "term": {
                              "fields.value": "2015-07-10"
                           }
                        }
                     ]
                  }
               }
            }
         }
      }
   }
}
```

---

<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 6, 2017, 12:01am UTC](https://discuss.elastic.co/t/boolean-query/25351/6 "2017-07-06T00:01:32Z")

</div>


