# Search with exact phrase in my index

**URL:** <https://discuss.elastic.co/t/search-with-exact-phrase-in-my-index/351213>\
**Category:** Elasticsearch\
**Created:** [January 16, 2024, 11:27pm UTC](https://discuss.elastic.co/t/search-with-exact-phrase-in-my-index/351213 "2024-01-16T23:27:55Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Indilya](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/indilya/32/122260_2.png) [@Indilya](https://discuss.elastic.co/u/Indilya)\
**Post date:** [January 16, 2024, 11:27pm UTC](https://discuss.elastic.co/t/search-with-exact-phrase-in-my-index/351213/1 "2024-01-16T23:27:55Z")

</div>

Hello,

First of all I want to apologize if my post is not correct. This is my first time on this forum and my first time using Elastic Search.

I also take this opportunity to thank you in advance for the help.

I have an index of more than 32 million records and although it may seem simple, I want to do an exact search for a word.

I use Elastic Search 8.11.3.

I leave some information here in case it can be of help to you.

```auto
{
  "mappings": {
    "dynamic": "true",
    "dynamic_templates": [
      {
        "all_text_fields": {
          "match_mapping_type": "string",
          "mapping": {
            "analyzer": "iq_text_base",
            "fields": {
              "delimiter": {
                "analyzer": "iq_text_delimiter",
                "type": "text",
                "index_options": "freqs"
              },
              "joined": {
                "search_analyzer": "q_text_bigram",
                "analyzer": "i_text_bigram",
                "type": "text",
                "index_options": "freqs"
              },
              "prefix": {
                "search_analyzer": "q_prefix",
                "analyzer": "i_prefix",
                "type": "text",
                "index_options": "docs"
              },
              "enum": {
                "ignore_above": 2048,
                "type": "keyword"
              },
              "stem": {
                "analyzer": "iq_text_stem",
                "type": "text"
              }
            }
          }
        }
      }
    ],
    "properties": {
      "id_key": {
        "type": "long"
      },
      "keyword": {
        "type": "text",
        "fields": {
          "delimiter": {
            "type": "text",
            "index_options": "freqs",
            "analyzer": "iq_text_delimiter"
          },
          "enum": {
            "type": "keyword",
            "ignore_above": 2048
          },
          "joined": {
            "type": "text",
            "index_options": "freqs",
            "analyzer": "i_text_bigram",
            "search_analyzer": "q_text_bigram"
          },
          "prefix": {
            "type": "text",
            "index_options": "docs",
            "analyzer": "i_prefix",
            "search_analyzer": "q_prefix"
          },
          "stem": {
            "type": "text",
            "analyzer": "iq_text_stem"
          }
        },
        "analyzer": "iq_text_base"
      },
      "web_id": {
        "type": "long"
      }
    }
  }
}

```

I also attach an image of the document.

 ![Captura de pantalla 2024-01-16 a las 23.15.28](https://us1.discourse-cdn.com/elastic/original/3X/c/d/cdf406dec5667db730b94137eeb5f95d664701ec.png)

I simply want to do a search called "snow swnow" and only see the exact phrase within "keyword."

I have been reading for days and what worries me most is that I should delete my index and create a new one since I have more than 33 million records.

How can I do the search I need?

Thank you very much for the help.

---

<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:** [January 17, 2024, 3:36am UTC](https://discuss.elastic.co/t/search-with-exact-phrase-in-my-index/351213/2 "2024-01-17T03:36:02Z")

</div>

I think you can search for exact matches in the field keyword.enum.

---

<div class="post-metadata">

**Author:** ![Indilya](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/indilya/32/122260_2.png) [@Indilya](https://discuss.elastic.co/u/Indilya)\
**Post date:** [January 17, 2024, 7:38am UTC](https://discuss.elastic.co/t/search-with-exact-phrase-in-my-index/351213/3 "2024-01-17T07:38:39Z")

</div>

Hello,

What would it be like then?

I want to search for "snow snow" as a keyword.

So is it possible?

Thank you

---

<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:** [January 17, 2024, 8:15am UTC](https://discuss.elastic.co/t/search-with-exact-phrase-in-my-index/351213/4 "2024-01-17T08:15:31Z")

</div>

You should be able to use a term query on the keyword.enum field, e.g.:

```auto
GET /_search
{
  "query": {
    "term": {
      "keyword.enum": {
        "value": "snow snow"
      }
    }
  }
}

```

---

<div class="post-metadata">

**Author:** ![Indilya](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/indilya/32/122260_2.png) [@Indilya](https://discuss.elastic.co/u/Indilya)\
**Post date:** [January 17, 2024, 9:44am UTC](https://discuss.elastic.co/t/search-with-exact-phrase-in-my-index/351213/5 "2024-01-17T09:44:24Z")

</div>

> [@Christian\_Dahlqvist](#):
>
> `term`

Hello,

I greatly appreciate the help.

Now I want to combine it with the query I already have.

Right now I do it this way:

```auto
GET /_search
{
    "query": {
      "bool": {
        "must": {
          "match": {
            "web_id": "3593"
          }
        },
        "filter": [
          {
            "bool": {
              "must": [
                {
                  "bool": {
                    "should": [
                      {
                        "match_phrase": { "keyword": "casa"}
                      },
                      {
                        "match_phrase": { "keyword": "coche"}
                      }
                    ]
                  }
                }
              ]
            }
          }
        ]
      }
    }
  }

```

I want the following:

1. Look for the web\_id with ID 3593.
2. Let it find all the phrases with an exact match as long as it has the web\_id ID 3593.
3. Possibility of multiple keywords as in my example.

My code does it but it doesn't have an exact match.

How could I do it?

Thank you

---

<div class="post-metadata">

**Author:** ![Indilya](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/indilya/32/122260_2.png) [@Indilya](https://discuss.elastic.co/u/Indilya)\
**Post date:** [January 17, 2024, 9:49am UTC](https://discuss.elastic.co/t/search-with-exact-phrase-in-my-index/351213/6 "2024-01-17T09:49:40Z")

</div>

Hello!

I bring good news.

It worked for me with this code:

```auto
GET /_search
{
    "query": {
      "bool": {
        "must": {
          "match": {
            "web_id": "3593"
          }
        },
        "filter": [
          {
            "bool": {
              "must": [
                {
                  "bool": {
                    "should": [
                      {
                        "term": { "keyword.enum": { "value": "snow snow" } }
                      },
                      {
                        "term": { "keyword.enum": { "value": "cisterna baja" } }
                      }
                    ]
                  }
                }
              ]
            }
          }
        ]
      }
    }
  }

```

Is it correct?

Thank you

---

<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:** [January 17, 2024, 9:56am UTC](https://discuss.elastic.co/t/search-with-exact-phrase-in-my-index/351213/7 "2024-01-17T09:56:31Z")

</div>

Yes but I'd simplify this a bit:

```auto
GET /_search
{
    "query": {
      "bool": {
        "filter": [
           {
          "term": {
            "web_id": "3593"
          }
         },
          {
                  "bool": {
                    "should": [
                      {
                        "term": { "keyword.enum": { "value": "snow snow" } }
                      },
                      {
                        "term": { "keyword.enum": { "value": "cisterna baja" } }
                      }
                    ]
                  }
          }
        ]
      }
    }
  }

```

---

<div class="post-metadata">

**Author:** ![Indilya](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/indilya/32/122260_2.png) [@Indilya](https://discuss.elastic.co/u/Indilya)\
**Post date:** [January 17, 2024, 10:08am UTC](https://discuss.elastic.co/t/search-with-exact-phrase-in-my-index/351213/8 "2024-01-17T10:08:58Z")

</div>

Excellent, the problem is now solved.

I greatly appreciate the 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:** [February 14, 2024, 10:09am UTC](https://discuss.elastic.co/t/search-with-exact-phrase-in-my-index/351213/9 "2024-02-14T10:09:57Z")

</div>

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