# Is it possible to return only one result if an exact match is found?

**URL:** <https://discuss.elastic.co/t/is-it-possible-to-return-only-one-result-if-an-exact-match-is-found/216410>\
**Category:** Elasticsearch\
**Created:** [January 24, 2020, 11:44am UTC](https://discuss.elastic.co/t/is-it-possible-to-return-only-one-result-if-an-exact-match-is-found/216410 "2020-01-24T11:44:38Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Aaron\_Pitts](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/aaron_pitts/32/61030_2.png) [@Aaron\_Pitts](https://discuss.elastic.co/u/Aaron_Pitts)\
**Post date:** [January 24, 2020, 11:44am UTC](https://discuss.elastic.co/t/is-it-possible-to-return-only-one-result-if-an-exact-match-is-found/216410/1 "2020-01-24T11:44:38Z")

</div>

Hi guys,

I'm building a site with a database of watches. I have an autocomplete search input. I have fuzzy matching for typing in the watch name (`post_title`), but I'd like for the user to be able to enter the watch reference if they have it, this would show just one result if there was an exact match. Is it possible to return just one result if a certain match is found matching the `meta.reference.raw` field, and if no match is found for that field fall back to the fuzzy search for the `post_title` field?

Example of the data below:

```
{
  "_index": "twptestwp-post-1",
  "_type": "_doc",
  "_id": "32567",
  "_source": {
    "post_id": 32567,
    "ID": 32567,
    "post_title": "ROYAL OAK OFFSHORE DIVER",
    "meta": {
      "reference": [
        {
          "value": "15710ST.OO.A010CA.01",
          "raw": "15710ST.OO.A010CA.01",
          "boolean": false,
          "date": "1971-01-01",
          "datetime": "1971-01-01 00:00:01",
          "time": "00:00:01"
        }
      ]
    }
  }
}

```

Many thanks

---

<div class="post-metadata">

**Author:** ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)\
**Post date:** [January 27, 2020, 10:36am UTC](https://discuss.elastic.co/t/is-it-possible-to-return-only-one-result-if-an-exact-match-is-found/216410/2 "2020-01-27T10:36:26Z")

</div>

hey,

if you really only want a single result, then you need to execute an exact search first.

if you want to score an exact match higher (but still find the other documents), you may want to take a look at the `should` query as part of the `bool` query.

--Alex

---

<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:** [February 24, 2020, 10:36am UTC](https://discuss.elastic.co/t/is-it-possible-to-return-only-one-result-if-an-exact-match-is-found/216410/3 "2020-02-24T10:36:34Z")

</div>

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