json - Elasticsearch: completion sorting by the number of matched documents -
i implementing tag autocompleter elasticsearch. tags stored inside indexed documents in various string arrays:
{ ... "skills": { "industries_solutions": [ "project-management" ], "skills_competencies": [ "javascript" ], "highlighted": [], "tag_suggest": { "input": [ "javascript", "hibernate", "project-management" ] }, "job_roles": [ "hibernate" ] } }
as can see, included them in tag_suggest object , mapped in way able query _suggest api kind of queries:
{ "tag_suggest":{ "text":"jav", "completion": { "field" : "skills.tag_suggest", "fuzzy" : { "fuzziness" : 1 } } } }
which correctly returns:
{ "_shards": { "total": 5, "successful": 5, "failed": 0 }, "tag_suggest": [ { "text": "jav", "offset": 0, "length": 3, "options": [ { "text": "java", "score": 1 }, { "text": "javascript", "score": 1 } ] } ] }
what able sort results basing on number of matched documents. example, if "java" tag included in 1 document , javascript included in 10 documents, latter appear first suggestion result. nice have number of matched documents, sort of stackoverflow-like. how implement feature? completion correct way go? thank you.
Comments
Post a Comment