# Exact match Query: ex: When I am trying to search for marble flooring the following matches should be fetched

**URL:** <https://discuss.elastic.co/t/exact-match-query-ex-when-i-am-trying-to-search-for-marble-flooring-the-following-matches-should-be-fetched/352589>\
**Category:** Elasticsearch\
**Created:** [February 6, 2024, 4:50am UTC](https://discuss.elastic.co/t/exact-match-query-ex-when-i-am-trying-to-search-for-marble-flooring-the-following-matches-should-be-fetched/352589 "2024-02-06T04:50:45Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mohan\_T](https://avatars.discourse-cdn.com/v4/letter/m/34f0e0/32.png) [@Mohan\_T](https://discuss.elastic.co/u/Mohan_T)\
**Post date:** [February 6, 2024, 4:50am UTC](https://discuss.elastic.co/t/exact-match-query-ex-when-i-am-trying-to-search-for-marble-flooring-the-following-matches-should-be-fetched/352589/1 "2024-02-06T04:50:45Z")

</div>

When I am trying to search for marble flooring the following matches should be fetched

1. marble flooring
2. marbles flooring
3. flooring marble
4. flooring marbles
5. marble floor
6. marbles floor
7. marble
8. marbles
9. flooring
10. floor

```auto
{
  "size": 100,
  "query": {
      "bool": {
          "must": [
              {
                  "multi_match": {
                      "query": "marble flooring",
                      "fields": [
                          "title^3",
                          "keywords.key_value^2",
                          "services.name^1"
                      ],
                      "type": "best_fields",
                      "operator": "and"
                  }
              }
          ]
      }
  }
}

```

as I dont want to use fuzziness, due to fuzziness. when am searching for a table, in the results i am getting the results for cable as well

---

<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:** [February 6, 2024, 6:17am UTC](https://discuss.elastic.co/t/exact-match-query-ex-when-i-am-trying-to-search-for-marble-flooring-the-following-matches-should-be-fetched/352589/2 "2024-02-06T06:17:03Z")

</div>

What is the mapping of the fields you are searching? Based on your expected matches it looks like you may need to use a custom analyser that includes a stemmer.

---

<div class="post-metadata">

**Author:** ![Mohan\_T](https://avatars.discourse-cdn.com/v4/letter/m/34f0e0/32.png) [@Mohan\_T](https://discuss.elastic.co/u/Mohan_T)\
**Post date:** [February 6, 2024, 6:25am UTC](https://discuss.elastic.co/t/exact-match-query-ex-when-i-am-trying-to-search-for-marble-flooring-the-following-matches-should-be-fetched/352589/3 "2024-02-06T06:25:27Z")

</div>

**mappings**

```auto
"keywords": {
    "type": "object",
    "enabled": True,
    "properties": {
        "name": {
            "type": "text",
            "analyzer": "synonym_analyzer"
        }
    }
}

```

**settings**

```auto
"analyzer": {
    "synonym_analyzer": {
    "tokenizer": "whitespace",
    "filter": ["stemmer"]
    }
}

```

this the the mapping and analyzer which i have used

---

<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:** [February 6, 2024, 6:46am UTC](https://discuss.elastic.co/t/exact-match-query-ex-when-i-am-trying-to-search-for-marble-flooring-the-following-matches-should-be-fetched/352589/4 "2024-02-06T06:46:59Z")

</div>

Can you please use the [get mapping API](https://www.elastic.co/guide/en/elasticsearch/reference/8.12/indices-get-mapping.html) to show us the exact mapping of the 3 fields you are querying? This should allow you to verify that the fields you are querying actually have the mapping you showed.

Once you have done this you can use the [analyze API](https://www.elastic.co/guide/en/elasticsearch/reference/8.12/test-analyzer.html) to test how your analyzer tokenizes the various string you query with and expect to match.

---

<div class="post-metadata">

**Author:** ![Mohan\_T](https://avatars.discourse-cdn.com/v4/letter/m/34f0e0/32.png) [@Mohan\_T](https://discuss.elastic.co/u/Mohan_T)\
**Post date:** [February 6, 2024, 7:10am UTC](https://discuss.elastic.co/t/exact-match-query-ex-when-i-am-trying-to-search-for-marble-flooring-the-following-matches-should-be-fetched/352589/5 "2024-02-06T07:10:11Z")

</div>

mappings

```auto
"keywords": {
    "properties": {
        "keyword_values": {
            "type": "text",
            "fields": {
                "keyword": {
                    "type": "keyword",
                    "ignore_above": 256
                }
            }
        },
        "name": {
            "type": "text",
            "analyzer": "synonym_analyzer"
        }
    }
}

```

analyze

```auto
{
    "tokens": [
        {
            "token": "marbl",
            "start_offset": 0,
            "end_offset": 6,
            "type": "word",
            "position": 0
        },
        {
            "token": "floor",
            "start_offset": 7,
            "end_offset": 15,
            "type": "word",
            "position": 1
        }
    ]
}

```

---

<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:** [February 6, 2024, 7:28am UTC](https://discuss.elastic.co/t/exact-match-query-ex-when-i-am-trying-to-search-for-marble-flooring-the-following-matches-should-be-fetched/352589/6 "2024-02-06T07:28:45Z")

</div>

> [@Mohan\_T](#):
>
> ```auto
> "fields": [
> "title^3",
> "keywords.key_value^2",
> "services.name^1"
> 
> ```

It looks like you are not searching the `keywords.name` field which is the one with the custom analyser and instead are searching the `keywords.keyword_values` field, which uses the default analyser and has no stemmer.

---

<div class="post-metadata">

**Author:** ![Mohan\_T](https://avatars.discourse-cdn.com/v4/letter/m/34f0e0/32.png) [@Mohan\_T](https://discuss.elastic.co/u/Mohan_T)\
**Post date:** [February 6, 2024, 9:20am UTC](https://discuss.elastic.co/t/exact-match-query-ex-when-i-am-trying-to-search-for-marble-flooring-the-following-matches-should-be-fetched/352589/7 "2024-02-06T09:20:10Z")

</div>

mappings

```auto
"keywords": {
    "properties": {
        "name": {
            "type": "text",
            "fields": {
                "keyword": {
                    "type": "keyword",
                    "ignore_above": 256
                }
            }
        },
        "name": {
            "type": "text",
            "analyzer": "synonym_analyzer"
        }
    }
}

```

analyze

```auto
{
    "tokens": [
        {
            "token": "marbl",
            "start_offset": 0,
            "end_offset": 6,
            "type": "word",
            "position": 0
        },
        {
            "token": "floor",
            "start_offset": 7,
            "end_offset": 15,
            "type": "word",
            "position": 1
        }
    ]
}

```

this is the updated one

---

<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:** [February 6, 2024, 9:31am UTC](https://discuss.elastic.co/t/exact-match-query-ex-when-i-am-trying-to-search-for-marble-flooring-the-following-matches-should-be-fetched/352589/8 "2024-02-06T09:31:32Z")

</div>

Where are the mappings coming from? It looks like you have a duplicate `name` field definition (not valid JSON), which makes me suspect it is not part of the output from the get mappings API.

---

<div class="post-metadata">

**Author:** ![Mohan\_T](https://avatars.discourse-cdn.com/v4/letter/m/34f0e0/32.png) [@Mohan\_T](https://discuss.elastic.co/u/Mohan_T)\
**Post date:** [February 6, 2024, 11:04am UTC](https://discuss.elastic.co/t/exact-match-query-ex-when-i-am-trying-to-search-for-marble-flooring-the-following-matches-should-be-fetched/352589/9 "2024-02-06T11:04:51Z")

</div>

{{URL}}/indexname/\_mapping

```auto
{
    "indexname": {
        "mappings": {
            "properties": {
                "keywords": {
                    "properties": {
                        "key_name": {
                            "type": "text",
                            "fields": {
                                "keyword": {
                                    "type": "keyword",
                                    "ignore_above": 256
                                }
                            }
                        },
                        "name": {
                            "type": "text",
                            "analyzer": "synonym_stemmer_bad_words_analyzer"
                        }
                    }
                }
            }
        }
    }
}

```

from here i got the response

---

<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:** [February 6, 2024, 11:54am UTC](https://discuss.elastic.co/t/exact-match-query-ex-when-i-am-trying-to-search-for-marble-flooring-the-following-matches-should-be-fetched/352589/10 "2024-02-06T11:54:39Z")

</div>

Here you can see that the two properties are named `key_name` and `name`, which is different from the previous post. To use the stemmer you need to query the `keywords.name` field and not `keywords.key_name` . The query you posted shows you querying `keywords.key_value`, which apparently does not exist.

If you are going to alter the output and not show real field names please make sure it is correct.

---

<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:** [March 5, 2024, 11:54am UTC](https://discuss.elastic.co/t/exact-match-query-ex-when-i-am-trying-to-search-for-marble-flooring-the-following-matches-should-be-fetched/352589/11 "2024-03-05T11:54:50Z")

</div>

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