Elasticsearch filter via number of mentions

2019-04-17 15:23发布

问题:

I am trying to write a query which will return me articles about certain keywords but I want the articles to only show if the the given keyword is mentions 5 times in the articles I am using following query But no result

  {
   "query":{

      "multi_match":{
         "query":"Apple",
         "operator":"AND",
         "fields":[
            "Text"
         ]

      }
      ,"min_term_freq" : 5
   },
   "sort":{
      "Date":{
         "order":"desc"
      }
   }
}

回答1:

I dont believe there is any min_term_freq option as you have listed. But then you can use scripting in filter to achieve the same -

{
  "query": {
    "filtered": {
      "filter": {
        "script": {
          "script": "_index['Text']['apple'].tf() > 5"
        }
      }
    }
  }
}