Elasticsearch filter via number of mentions
Asked Answered
V

1

0

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"
      }
   }
}
Vegetal answered 3/2, 2015 at 10:13 Comment(0)
M
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"
        }
      }
    }
  }
}
Minion answered 4/2, 2015 at 2:33 Comment(6)
Your query is working fine but if I change the word from apple to any other it doesn't work.Vegetal
It should be an exisitng term ... What other term did you try >Minion
I think i got the problem this query is not accepting two words like, tim took. So how do I solve that?Vegetal
This only accepts tokenized terms like tim or took , and not "tim took"Minion
Write an AND condition _index['Text']['time'].tf() > 5 && _index['Text']['took'].tf() > 5Minion
The query is working fine now but it is not sorting data as per timeVegetal

© 2022 - 2024 — McMap. All rights reserved.