How to filter results based on frequency of repeating terms in an array in elasticsearch -


i have array field lot of keywords , need sort documents on basis on how many times particular keyword repetation in arrays. eg,if field name "nationality" , document 1, consists of following doc1 nationality :

["us","uk","australia","india","us","us"] 

and doc2 nationality:

["us","uk","us","us","us","china"] 

i want documents shown term "us" occurs more 3 times. make doc2 shown. how this?

you can use scripting implemented.

{       "query": {         "filtered": {           "filter": {             "script": {               "script": "_index['nationality']['us'].tf() > 3"             }           }         }       }     } 

here in scripy array "nationality" checked term "us" , count taken tf (term frequency). documents term frequency greater 3 shown in results. can learn more filter operations here


Comments

Popular posts from this blog

twig - Using Twigbridge in a Laravel 5.1 Package -

Kivy: Swiping (Carousel & ScreenManager) -

jdbc - Not able to establish database connection in eclipse -