elasticsearch match all words from document in the search query

后端 未结 2 1958
-上瘾入骨i
-上瘾入骨i 2020-12-15 08:25

We can search for ALL words in a specific document.field like this:

{ \"query\" : { \"match\" : { \"title\": { \"query\" : \"Black Nike Mens\", \"operator\"          


        
2条回答
  •  失恋的感觉
    2020-12-15 09:13

    I finally got it to work but not with a direct method!

    This is what I do:

    • Create a clean list of words from the source query, by:
      • change to lower case
      • replacing any special chars and punctuation with space
      • remove duplicate words
    • Search using normal match with OR operator for the words joined as a string
    • Now we will find the best relevant hits in result
    • We take those hits one by one and do a word to word search in php (or whatever programming language you use)
    • This word search will check for all the words of a document from the hits we just found, and match them with the words in source query; such that all words from hit document should be present in the source query string

    This worked for me well enough!

    Unless someone has a direct method from elasticsearch query language.

提交回复
热议问题