# Exact search results not shown at the top

**URL:** <https://discuss.elastic.co/t/exact-search-results-not-shown-at-the-top/154211>\
**Category:** Elasticsearch\
**Created:** [October 26, 2018, 1:59pm UTC](https://discuss.elastic.co/t/exact-search-results-not-shown-at-the-top/154211 "2018-10-26T13:59:41Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Veenudheepithi\_Muthu](https://avatars.discourse-cdn.com/v4/letter/v/5daacb/32.png) [@Veenudheepithi\_Muthu](https://discuss.elastic.co/u/Veenudheepithi_Muthu)\
**Post date:** [October 26, 2018, 1:59pm UTC](https://discuss.elastic.co/t/exact-search-results-not-shown-at-the-top/154211/1 "2018-10-26T13:59:41Z")

</div>

I am using Elasticsearch version 5.2. When I try to query a combination of two words that are stored in two different attributes, I get the search result but the record with the exact search words are not displayed at the top.  
For example I have two names saved in ES  
Document 1: "firstName" : "Joe"  
"lastName" : "Root"  
Document 2: "firstName" : "Joe"  
"lastName" : "Martin"  
If my search word is "Joe Root", I get "Joe Martin" as the first search result and "Joe Root" as the second search result. But I want "Joe Root" to be the first one.  
I tried with the combination of bool and term query then with multi match query. I also tried by boosting the score of the field. But nothing worked.  
Can I get assistance on how to resolve the issue?

---

<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:** [October 26, 2018, 3:13pm UTC](https://discuss.elastic.co/t/exact-search-results-not-shown-at-the-top/154211/2 "2018-10-26T15:13:21Z")

</div>

Could you provide a full recreation script as described in [About the Elasticsearch category](https://discuss.elastic.co/t/about-the-elasticsearch-category/21). It will help to better understand what you are doing. Please, try to keep the example as simple as possible.

A full reproduction script will help readers to understand, reproduce and if needed fix your problem. It will also most likely help to get a faster answer.

Also make sure in your tests that you are using one single shard instead of the default 5 ones.

---

<div class="post-metadata">

**Author:** ![Veenudheepithi\_Muthu](https://avatars.discourse-cdn.com/v4/letter/v/5daacb/32.png) [@Veenudheepithi\_Muthu](https://discuss.elastic.co/u/Veenudheepithi_Muthu)\
**Post date:** [October 29, 2018, 9:38am UTC](https://discuss.elastic.co/t/exact-search-results-not-shown-at-the-top/154211/3 "2018-10-29T09:38:30Z")

</div>

```
I tested my sample in only one shard but it didn't work.
Here is my script

**Mapping:**
{
  "users": {
"dynamic": "false",
"_all": {
  "enabled": false
},
"properties": {
  "creationDate": {
    "type": "date",
    "format": "yyyy-MM-dd HH:mm:ss"
  },
  "firstName": {
    "type": "string",
    "fields": {
      "indexed": {
        "type": "string"
      },
      "sortable": {
        "type": "string"
      },
      "untouched": {
        "type": "string",
        "index": "not_analyzed"
      }
    }
  },
  "lastName": {
    "type": "string",
    "fields": {
      "indexed": {
        "type": "string"
      },
      "sortable": {
        "type": "string"
      },
      "untouched": {
        "type": "string",
        "index": "not_analyzed"
      }
    }
  }
}
  }
}

**Search Query:**
GET /users/users/_search
{
"query": {
    "multi_match" : {
      "query": "Joe Martin", 
      "fields": ["firstName", "lastName"] 
    }
}
}

**Search Results:**
{
  "took": 6,
  "timed_out": false,
  "_shards": {
"total": 1,
"successful": 1,
"failed": 0
  },
  "hits": {
"total": 3,
"max_score": 0.6931472,
"hits": [
  {
    "_index": "users",
    "_type": "users",
    "_id": "1",
    "_score": 0.6931472,
    "_source": {
      "firstName": "Joe",
      "lastName": "Root"
    }
  },
  {
    "_index": "users",
    "_type": "users",
    "_id": "2",
    "_score": 0.6931472,
    "_source": {
      "firstName": "Joe",
      "lastName": "Martin"
    }
  },
  {
    "_index": "users",
    "_type": "users",
    "_id": "3",
    "_score": 0.6931472,
    "_source": {
      "firstName": "Anna",
      "lastName": "Martin"
    }
  }
]
  }
}

My search text "Joe Martin" should be my first record but I get it as the second result.
```

---

<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:** [October 29, 2018, 9:48am UTC](https://discuss.elastic.co/t/exact-search-results-not-shown-at-the-top/154211/4 "2018-10-29T09:48:08Z")

</div>

As per [the docs,](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-multi-match-query.html#multi-match-types) the default matching behaviour assumes you are looking for all terms in a single field:

> "Finds documents which match any field, but uses the \_score from the best field"

So the match on the lastname in this case is worthless.  
Searches like your example tend to work best with the "cross-fields" type (although in this particular case you have picked a lastname "Martin" that is likely to be a popular firstname so will be lowly scored)

---

<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:** [November 26, 2018, 9:58am UTC](https://discuss.elastic.co/t/exact-search-results-not-shown-at-the-top/154211/5 "2018-11-26T09:58:26Z")

</div>

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