Search with exact phrase in my index

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.

{
  "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.

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.

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

Hello,

What would it be like then?

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

So is it possible?

Thank you

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

GET /_search
{
  "query": {
    "term": {
      "keyword.enum": {
        "value": "snow snow"
      }
    }
  }
}
2 Likes

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:

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

Hello!

I bring good news.

It worked for me with this code:

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

Yes but I'd simplify this a bit:

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

Excellent, the problem is now solved.

I greatly appreciate the help.

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