Elasticsearch Java API MoreLikeThis not returning documents compared to "_search" rest endpoint -
intention: elasticsearch java morelikethis query in java below raw more_like_this
filtered query via /_search
rest endpoint doing.
get /index/type/_search { "query": { "filtered": { "query": { "more_like_this": { "fields": [ "title", "body", "description", "organisations", "locations" ], "min_term_freq": 2, "max_query_terms": 25, "ids": [ "http://xxx/doc/doc" ] } }, "filter": { "range": { "datepublished": { "gte": "2016-01-01t12:30:00+01:00" } } } } }, "fields": [ "title", "description", "datepublished" ] }
and java implementation above:
filteredquerybuilder querybuilder = new filteredquerybuilder(querybuilders.matchallquery(),filterbuilders.rangefilter("datepublished").gte(("2016-01-01t12:30:00+01:00"))); searchsourcebuilder query = searchsourcebuilder.searchsource().query(querybuilder); return client.preparemorelikethis("index", "type", "http://xxx/doc/doc") .setfield("title", "description", "body", "organisations","locations") .setmintermfreq(2) .maxqueryterms(25) .setsearchsource(query);
however, results far differ more_like_this
rest endpoint returning. getting matches of 4/5th of whole documents in index. if none of filters being applied
targeting es v1.4.2
, v1.6.2
any advice please.thanks
i got desire results querybuilders.morelikethisquery()
. inspirations post here.
filterbuilder filterbuilder = filterbuilders.rangefilter("datepublished") .gte("2016-01-01t12:30:00+01:00") .includelower(false).includeupper(false); morelikethisquerybuilder mltquerybuilder = querybuilders.morelikethisquery("title", "description", "body", "organisations","locations") .mintermfreq(2) .maxqueryterms(25) .ids("http://xxx/doc/doc"); searchrequestbuilder searchrequestbuilder = client.preparesearch("index"); searchrequestbuilder.settypes("type"); searchrequestbuilder.addfields("title","description","datepublished"); searchrequestbuilder.setquery(mltquerybuilder).setpostfilter(filterbuilder); searchrequestbuilder.execute().actionget()
notes:
querybuilders
seems way forward in terms of compatibility es v2.0 , beyound@morelikethisrequestbuilder
deprecated in es v1.6 + , removed in 2.0
Comments
Post a Comment