Elastic search Word delimeter

I got an elastic search engine in my project. I need to find an identifier with it. The problem is that this identifier got '-' inside. Elastic search makes a split with this character, searching by two strings instead one. For example:

Identifier: 023-019125 Elastic search split it and search by 023 and 019125, that's returns me many result that I don't want.

How can I make elastic search use an exact search only for this field. Here is my actual elastic search config:

Indexes:
    service:
        properties:
            identifier:
                type: text

In type field i tried keyword, text, regex

Upvotes: 0

Views: 28

Answers (1)

Hassaan Tariq
Hassaan Tariq

Reputation: 61

Define the identifier field as a keyword type. This ensures that the field is not tokenized and is treated as a single term.

PUT /your_index_name

{
    "mappings": {
        "properties": {
            "identifier": {
                "type": "keyword"
            }
        }
    }
}

Plus if you already have data indexed, you will need to reindex it to apply the new mapping. Reindexing involves creating a new index with the updated mapping and then copying data from the old index to the new one.

Upvotes: 2

Related Questions