Answer the question
In order to leave comments, you need to log in
How to index and apply negative particles in a query in Elasticsearch?
Good day!
There is a site that runs search for users, organized using Elasticsearch. By itself, it allows for advanced search constructs - for example, the phrase "tomatoes are green" will find all tomatoes that are not green. The problem starts from the moment when a regular user starts searching. He, of course, will look for "not green tomatoes", which, here's a surprise, will find exactly "green tomatoes".
A similar problem exists at the indexing stage. Since the encountered phrase "tomatoes are not green" elastic will index as ["tomatoes", "not", "green"] (and the word "not" is also found in stop filters) and, accordingly, quite successfully find it by the phrase "
1) Is it possible to make it so that when searching, it perceives the word "not" as a minus? That is, "not green" = "-green"?
2) And is it possible for him to perceive the word "not" at the stage of indexing as a negative particle?
By the way, I have googled this topic a lot. I thought about shingles, which allow indexing phrases, but they do not solve the problem, because:
1) they process only one single negative particle, and there can be several of them: "not", "without", etc.
2) the search phrases "not green" and "-green" will still work differently ("not green" will only search for sentences where the phrase "not green" is clearly found)
Answer the question
In order to leave comments, you need to log in
So it might be easier to do the replacement at the stage of receiving the search string? Not everything can be hung on an elastic ...
Moreover, there are very few of these particles, “not”, “neither”, “without”, “and”, “or” ...
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question