# Boolean Exact Query

**URL:** <https://discuss.elastic.co/t/boolean-exact-query/99726>\
**Category:** Elasticsearch\
**Created:** [September 7, 2017, 1:15pm UTC](https://discuss.elastic.co/t/boolean-exact-query/99726 "2017-09-07T13:15:37Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![trabs](https://avatars.discourse-cdn.com/v4/letter/t/9f8e36/32.png) [@trabs](https://discuss.elastic.co/u/trabs)\
**Post date:** [September 7, 2017, 1:15pm UTC](https://discuss.elastic.co/t/boolean-exact-query/99726/1 "2017-09-07T13:15:37Z")

</div>

Hi,

I am currently not understanding why a specific query won't work. This is what is being sent to elasticsearch:

```
{
        "query": {
                "constant_score": {
                        "filter": {
                                "bool": {
                                        "must": [{
                                                        "term": {
                                                                "domain": "FOO"
                                                        }
                                                },
                                                {
                                                        "term": {
                                                                "value": "2002353708^^^&2.16.756.5.30.1.100.4.2&ISO~41433^^^&2.00.3.4.1.3&BAR"
                                                        }
                                                }
                                        ]
                                }
                        }
                }
        }
}

```

I am trying to exactly match all documents having both, the value "2002....BAR" as well as the domain value "FOO".  
The requested document has a mapping where the fields "domain" and "value" are

```
...
          "domain" : {
            "type" : "text",
            "fields" : {
              "keyword" : {
                "type" : "keyword",
                "ignore_above" : 256
              }
            }
          },
...
          "value" : {
            "type" : "text",
            "fields" : {
              "keyword" : {
                "type" : "keyword",
                "ignore_above" : 256
              }
            }
          },...

```

Any ideas? I'm sure I'm missing something obvious...

Thanks you!  
Michael

---

<div class="post-metadata">

**Author:** ![Ivan](https://avatars.discourse-cdn.com/v4/letter/i/df788c/32.png) [@Ivan](https://discuss.elastic.co/u/Ivan)\
**Post date:** [September 7, 2017, 4:18pm UTC](https://discuss.elastic.co/t/boolean-exact-query/99726/2 "2017-09-07T16:18:06Z")

</div>

Use the domain.keyword/value.keyword fields instead of domain/value.

---

<div class="post-metadata">

**Author:** ![trabs](https://avatars.discourse-cdn.com/v4/letter/t/9f8e36/32.png) [@trabs](https://discuss.elastic.co/u/trabs)\
**Post date:** [September 8, 2017, 7:34am UTC](https://discuss.elastic.co/t/boolean-exact-query/99726/3 "2017-09-08T07:34:24Z")

</div>

Thanks Ivan! That should work (will test it later).

I wonder why this is the solution; is the value (without the keyword "qualification") analyzed by the default text analyzer and that's why not available to an exact query?

Best,  
Michael

---

<div class="post-metadata">

**Author:** ![Ivan](https://avatars.discourse-cdn.com/v4/letter/i/df788c/32.png) [@Ivan](https://discuss.elastic.co/u/Ivan)\
**Post date:** [September 8, 2017, 2:01pm UTC](https://discuss.elastic.co/t/boolean-exact-query/99726/4 "2017-09-08T14:01:49Z")

</div>

Correct. Using the default analyzer, the value for domain will be  
lowercased to "foo". Term queries are using for exact matches, so they  
should be used on non-strings, non-analyzed strings (keyword), or strings  
with a keyword tokenizer.

GET /\_analyze  
{  
"text" :  
"2002353708^^^&2.16.756.5.30.1.100.4.2&ISO~41433^^^&2.00.3.4.1.3&BAR"  
}

{  
"tokens": [  
{  
"token": "2002353708",  
"start\_offset": 0,  
"end\_offset": 10,  
"type": "",  
"position": 0  
},  
{  
"token": "2.16.756.5.30.1.100.4.2",  
"start\_offset": 14,  
"end\_offset": 37,  
"type": "",  
"position": 1  
},  
{  
"token": "iso",  
"start\_offset": 38,  
"end\_offset": 41,  
"type": "",  
"position": 2  
},  
{  
"token": "41433",  
"start\_offset": 42,  
"end\_offset": 47,  
"type": "",  
"position": 3  
},  
{  
"token": "2.00.3.4.1.3",  
"start\_offset": 51,  
"end\_offset": 63,  
"type": "",  
"position": 4  
},  
{  
"token": "bar",  
"start\_offset": 64,  
"end\_offset": 67,  
"type": "",  
"position": 5  
}  
]  
}

---

<div class="post-metadata">

**Author:** ![trabs](https://avatars.discourse-cdn.com/v4/letter/t/9f8e36/32.png) [@trabs](https://discuss.elastic.co/u/trabs)\
**Post date:** [September 10, 2017, 10:54am UTC](https://discuss.elastic.co/t/boolean-exact-query/99726/5 "2017-09-10T10:54:06Z")

</div>

Thanks a lot Ivan, this helps 🙂

---

<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:** [October 8, 2017, 10:54am UTC](https://discuss.elastic.co/t/boolean-exact-query/99726/6 "2017-10-08T10:54:24Z")

</div>

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