We can search for ALL words in a specific document.field like this:
{ "query" : { "match" : { "title": { "query" : "Black Nike Mens", "operator" : "and" } } } }
This will search for the words Black
, Nike
and Mens
in the field title
such that only those documents are returned that will have ALL these words in the title
field.
But what I am trying to do is a little different.
I want to lookup such that if all the words of the title
field of the document are present in my search query then it will return that document.
For e.g.
suppose there is a document with title : "Nike Free Sparq Mens White"
in the elasticsearch database
now if I search with a query : "Nike Free Sparq 09 - Mens - White/Black/Varsity Red"
then it should return this document, because all the words in the document.title do exist in my query
but if I search with a query : "Nike Free Lebron - Mens - White/Black"
then it should NOT return the document because my query has the word Sparq
missing
this is a sort of reverse-and-operator search
Is this possible? If yes, then how?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…