# Exact word search

**URL:** https://discuss.elastic.co/t/exact-word-search/229457
**Category:** Elasticsearch
**Created:** [April 23, 2020, 11:34am UTC](https://discuss.elastic.co/t/exact-word-search/229457 "2020-04-23T11:34:04Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![smiler](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/smiler/32/66965_2.png) [@smiler](https://discuss.elastic.co/u/smiler)
#### Post date: [April 23, 2020, 11:34am UTC](https://discuss.elastic.co/t/exact-word-search/229457/1 "2020-04-23T11:34:05Z")

</div>

Hi.  
I need help with exact search. In some cases I need to search phrase includes word, in some cases I need to find documents where field value matches exactly search query.

For example, I have this documents:

```auto
{"match_all": {}}

"hits": [{"_id": "0", "_index": "test_index", "_score": 1.0, "_source": {"fields": {"target": "VALUE"}, "some_key": "value"}, "_type": "_doc"},
         {"_id": "1", "_index": "test_index", "_score": 1.0, "_source": {"fields": {"target": "TEST VALUE"}, "some_key": "value"}, "_type": "_doc"},
         {"_id": "2", "_index": "test_index", "_score": 1.0, "_source": {"fields": {"target": "VALUE"}, "some_key": "value"}, "_type": "_doc"},
         {"_id": "3", "_index": "test_index", "_score": 1.0, "_source": {"fields": {"target": "VALUE TEST"}, "some_key": "value"}, "_type": "_doc"},
         {"_id": "4", "_index": "test_index", "_score": 1.0, "_source": {"fields": {"target": "VALUE SOME"}, "some_key": "value"}, "_type": "_doc"}],
"max_score": 1.0,
"total": {"relation": "eq", "value": 5}

```

I need to filter documents where `fields.target` matches only "VALUE" (2 of 5 documents).  
How can I do that?  
The preferable method is `query_string`, but if it is not possible, other types ok too.

Mapping:

```auto
{
"test_index": {
    "mappings": {
        "properties": {
            "fields": {"properties": {"target": {"fields": {"keyword": {"ignore_above": 256, "type": "keyword"}}, "type": "text"}}},
            "some_key": {"fields": {"keyword": {"ignore_above": 256, "type": "keyword"}}, "type": "text"}}
            }
        }
    }
}

```

---

<div class="post-metadata">

### Author: ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)
#### Post date: [April 23, 2020, 1:35pm UTC](https://discuss.elastic.co/t/exact-word-search/229457/2 "2020-04-23T13:35:53Z")

</div>

Try to search on `fields.target.keyword` instead.

---

<div class="post-metadata">

### Author: ![smiler](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/smiler/32/66965_2.png) [@smiler](https://discuss.elastic.co/u/smiler)
#### Post date: [April 23, 2020, 2:07pm UTC](https://discuss.elastic.co/t/exact-word-search/229457/3 "2020-04-23T14:07:15Z")

</div>

Wow, thank you.

---

<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: [May 21, 2020, 2:07pm UTC](https://discuss.elastic.co/t/exact-word-search/229457/4 "2020-05-21T14:07:22Z")

</div>

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