# Disable fuzzy match ion matchquery on search and return only desired set of fields in response

**URL:** <https://discuss.elastic.co/t/disable-fuzzy-match-ion-matchquery-on-search-and-return-only-desired-set-of-fields-in-response/343030>\
**Category:** Elasticsearch\
**Created:** [September 14, 2023, 9:08am UTC](https://discuss.elastic.co/t/disable-fuzzy-match-ion-matchquery-on-search-and-return-only-desired-set-of-fields-in-response/343030 "2023-09-14T09:08:14Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tukaram](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/tukaram/32/118944_2.png) [@Tukaram](https://discuss.elastic.co/u/Tukaram)\
**Post date:** [September 14, 2023, 9:08am UTC](https://discuss.elastic.co/t/disable-fuzzy-match-ion-matchquery-on-search-and-return-only-desired-set-of-fields-in-response/343030/1 "2023-09-14T09:08:14Z")

</div>

1- In elastic java rest client, How I can disable the fuzzy match?

with below source builder, I need only properly matching records. if I give 456-ABC, it should not return anything.  
if I give just ABC or 123-ABC, it should return.

```auto

 SearchSourceBuilder sourceBuilder = new SearchSourceBuilder();
    sourceBuilder.query(QueryBuilders.boolQuery()
        .must(QueryBuilders.rangeQuery("insertTime").gte(todayStartTimestamp).lte(todayEndTimestamp))
        .must(QueryBuilders.matchQuery("id", "123-ABC"))
    );

```

2- Instead of returning entire payload, Can I just get specific matching field

---

<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:** [September 14, 2023, 9:59am UTC](https://discuss.elastic.co/t/disable-fuzzy-match-ion-matchquery-on-search-and-return-only-desired-set-of-fields-in-response/343030/2 "2023-09-14T09:59:00Z")

</div>

The problem here is related to your mapping. I believe that `id` is a `text` field and not a `keyword` field.

If you are using the default mapping, you can search in `id.keyword` instead. And use a `term` query instead of `match` although it will do the same thing.

---

<div class="post-metadata">

**Author:** ![Tukaram](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/tukaram/32/118944_2.png) [@Tukaram](https://discuss.elastic.co/u/Tukaram)\
**Post date:** [September 14, 2023, 10:21am UTC](https://discuss.elastic.co/t/disable-fuzzy-match-ion-matchquery-on-search-and-return-only-desired-set-of-fields-in-response/343030/3 "2023-09-14T10:21:16Z")

</div>

thanks, whats suggested/recommended data type for ID field?

---

<div class="post-metadata">

**Author:** ![Tukaram](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/tukaram/32/118944_2.png) [@Tukaram](https://discuss.elastic.co/u/Tukaram)\
**Post date:** [September 14, 2023, 10:22am UTC](https://discuss.elastic.co/t/disable-fuzzy-match-ion-matchquery-on-search-and-return-only-desired-set-of-fields-in-response/343030/4 "2023-09-14T10:22:15Z")

</div>

"id": {  
"type": "text",  
"fields": {  
"keyword": {  
"type": "keyword",  
"ignore\_above": 256  
}  
}  
},

this is my settings

---

<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:** [September 14, 2023, 11:04am UTC](https://discuss.elastic.co/t/disable-fuzzy-match-ion-matchquery-on-search-and-return-only-desired-set-of-fields-in-response/343030/5 "2023-09-14T11:04:42Z")

</div>

That's what I said. So if you don't want to change the mapping, try:

```auto
 SearchSourceBuilder sourceBuilder = new SearchSourceBuilder();
    sourceBuilder.query(QueryBuilders.boolQuery()
        .must(QueryBuilders.rangeQuery("insertTime").gte(todayStartTimestamp).lte(todayEndTimestamp))
        .must(QueryBuilders.termQuery("id.keyword", "123-ABC"))
    );

```

> [@Tukaram](#):
>
> whats suggested/recommended data type for ID field?

It depends on your use case, but if you want to search for exact content, I'd use a `keyword` type:

```auto
"id": {
  "type": "keyword"
}

```

---

<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 12, 2023, 11:05am UTC](https://discuss.elastic.co/t/disable-fuzzy-match-ion-matchquery-on-search-and-return-only-desired-set-of-fields-in-response/343030/6 "2023-10-12T11:05:21Z")

</div>

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