ElasticSearch : search more like this in java -
let's i've indexed document :
{ "_index": "indexapm", "_type": "membres", "_id": "3708", "_score": 1, "_source": { "firstname": "john", "lastname": "gueret-talon" } }
i want retrieve document when searching "guer", "gueret", "tal" example.
i have java application , tried :
morelikethisquerybuilder qb = querybuilders.morelikethisquery( "firstname^3", "lastname^3") .liketext("guer"); searchresponse response = client.preparesearch("myindex") .settypes("mytype") .setsearchtype(searchtype.dfs_query_and_fetch) .setquery(qb) // query .setfrom(0) .setsize(limit) .setexplain(true) .execute() .actionget();
but search doen't retrieve document. of course of study if seek exact match query , search "gueret", works.
does know kind of query have utilize , how create work java library? thanks!
the more query isn't best selection in case.
if, described, you're looking documents using first letters of words, should utilize prefix query instead, limited 1 field. search on more 1 field, utilize multimatch query (providing phrase_prefix
type). seek like:
querybuilders.multimatchquery("guer", "firstname", "lastname") .type(matchquerybuilder.type.phrase_prefix);
java elasticsearch
No comments:
Post a Comment