S
S
SwoDs2017-01-26 17:45:50
elasticsearch
SwoDs, 2017-01-26 17:45:50

How to search for a part of a word in ElasticSearch so that the second word is already searched for in a specific record?

There is a task, a directory of employees, you need to search for it
. For example, there are 2 entries:
1
fname = Maria
sname = Ivanova
2
fname = Maxim
sname = Plyushkin
We write Ma find 1 and 2 record
We write Ma Plus find 2 record

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
kotofey, 2017-01-26
@kotofey

I don’t know how compared to nGrams, you need to test, but there is an option to use fuzzy queries :

GET /_search
{
    "query": {
        "fuzzy" : {
            "fname" : {
                "value" :         "ма",
                "fuzziness" :     10, // этот параметр для вашей задачи нужно выставлять повыше
                "prefix_length" : 2, // будет равняться кол-ву уже введенных символов
                "max_expansions": 100 // также выставляется повыше
            }
        }
    }
}

But in general, such fuzzy fuzzy queries for the eraser are very "heavy". So this approach makes sense to use only if your database is not calculated in millions of records and / or gigabytes of occupied space.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question