# Search exact keyword from ES

**URL:** <https://discuss.elastic.co/t/search-exact-keyword-from-es/224594>\
**Category:** Elasticsearch\
**Created:** [March 23, 2020, 5:52am UTC](https://discuss.elastic.co/t/search-exact-keyword-from-es/224594 "2020-03-23T05:52:33Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sridhar](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sridhar/32/64860_2.png) [@Sridhar](https://discuss.elastic.co/u/Sridhar)\
**Post date:** [March 23, 2020, 5:52am UTC](https://discuss.elastic.co/t/search-exact-keyword-from-es/224594/1 "2020-03-23T05:52:33Z")

</div>

Hi,  
I'm using the below query to search and fetch the latest 1 record from ES

```auto
GET indexname/_search
{
   "query": {
    "dis_max": {
      "queries": [
        { "match": { "data.target.sampler.keyword": "CPU" }},
        { "match": { "data.row.Hostname.keyword": "HOSTNAME-21" }},
        { "match": { "data.name.keyword": "Average_cpu" }}
      ]
    }
  },
   "size": 1,
  "sort": [
    {
      "@timestamp": {
        "order": "desc"
      }
    }
  ]
}

```

but in result I'm getting different hostnames.. I expect the result to be only for the "data.row.Hostname.keyword" value

---

<div class="post-metadata">

**Author:** ![Christian\_Dahlqvist](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christian_dahlqvist/32/4617_2.png) [@Christian\_Dahlqvist](https://discuss.elastic.co/u/Christian_Dahlqvist)\
**Post date:** [March 23, 2020, 6:23am UTC](https://discuss.elastic.co/t/search-exact-keyword-from-es/224594/2 "2020-03-23T06:23:10Z")

</div>

The dismal query matched one or more of the queries so there is no guarantee the middle one must match. How come you are not using a Boolean query on terms instead?

---

<div class="post-metadata">

**Author:** ![Sridhar](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sridhar/32/64860_2.png) [@Sridhar](https://discuss.elastic.co/u/Sridhar)\
**Post date:** [March 23, 2020, 7:30am UTC](https://discuss.elastic.co/t/search-exact-keyword-from-es/224594/3 "2020-03-23T07:30:43Z")

</div>

Hi,  
Thanks for the response..

I tried bool must but no luck..

```auto
GET indexname/_search
{
   "_source": ["data.row.Hostname", "data.row.PerUtili"],
   "query": {
    "bool": {
		"must": [
		    { "match": { "data.target.sampler": "aaCPU" }},
		    { "match": {"data.row.Hostname": "HOSTNAME-21"}},
		    { "match": {"data.row.CPU": "Average_cpu"}}
      
		]
    }
  }, "size": 1,
    "sort": [
    {
      "@timestamp": {
        "order": "desc"
      }
    }
  ]
}

```

---

<div class="post-metadata">

**Author:** ![Sridhar](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sridhar/32/64860_2.png) [@Sridhar](https://discuss.elastic.co/u/Sridhar)\
**Post date:** [March 23, 2020, 7:36am UTC](https://discuss.elastic.co/t/search-exact-keyword-from-es/224594/4 "2020-03-23T07:36:39Z")

</div>

Hi.. Used keyword in bool must query.. it works now.

thanks for your help 🙂

---

<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 20, 2020, 7:36am UTC](https://discuss.elastic.co/t/search-exact-keyword-from-es/224594/5 "2020-04-20T07:36:47Z")

</div>

Closed on April 20, 2020, 7:36am UTC

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