简体   繁体   中英

elastic search query with lists of keywords

I want to perform a full-text search on the textfield of a number of documents stored in an elasticsearch database where the text field of the result documents have to contain a number of keywords and not contain a number of keywords. So I have 2 lists of strings called includes and excludes where all the strings in includes must be in the document and all the strings in excludes must not be in the documents text field.

Try bool query

{
  "query": {
    "bool" : {
      "must" : [{
        "term" : { "text" : "keyword1" }
      },{
        "term" : { "text" : "keyword2" }
      }],
      "must_not" :[{
        "term" : { "text" : "keyword3" }
      },{
        "term" : { "text" : "keyword4" }
      }]
    }
  }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM