Hello, I'm using MoreLikeThisRequestBuilder to prepare a query.
Everything works fine, but I need to filter the result. For example I
need to return all MLT documents but they must have certain value in
some field. In Solr I had filter query, do we have something like this
in ElasticSearch?
Thank you,
Eugene S.
You have two options: Either pass to setSearchSource a SearchSourceBuilder
initialized with a filter, or, build your own mlt by creating your own
search request that includes an mlt query (wrapped in other queries,
with/without filters), with the text for the mlt extracted from the
relevant doc you want.
On Fri, Dec 2, 2011 at 3:13 AM, Eugene Strokin eugene@strokin.info wrote:
Hello, I'm using MoreLikeThisRequestBuilder to prepare a query.
Everything works fine, but I need to filter the result. For example I
need to return all MLT documents but they must have certain value in
some field. In Solr I had filter query, do we have something like this
in Elasticsearch?
Thank you,
Eugene S.
Thank you, I've used the first option and it looks fine. Here is an
example for someone who would have such task in future:
SearchResponse
response=clientProvider.getClient().prepareMoreLikeThis(
clientProvider.getIndexName(), "post", postId)
.setField("text")
.setSearchSource(
SearchSourceBuilder.searchSource()
.query(QueryBuilders.matchAllQuery())
.filter(FilterBuilders.andFilter(
FilterBuilders.termFilter("imgWidth", 300),
FilterBuilders.termFilter("replica", false)))
)
.setMinTermFreq(1)
.setSearchFrom(0)
.setSearchSize(settings.getPostsOnPage())
.execute().actionGet();
On Dec 4, 9:03 am, Shay Banon kim...@gmail.com wrote:
You have two options: Either pass to setSearchSource a SearchSourceBuilder
initialized with a filter, or, build your own mlt by creating your own
search request that includes an mlt query (wrapped in other queries,
with/without filters), with the text for the mlt extracted from the
relevant doc you want.On Fri, Dec 2, 2011 at 3:13 AM, Eugene Strokin eug...@strokin.info wrote:
Hello, I'm using MoreLikeThisRequestBuilder to prepare a query.
Everything works fine, but I need to filter the result. For example I
need to return all MLT documents but they must have certain value in
some field. In Solr I had filter query, do we have something like this
in Elasticsearch?
Thank you,
Eugene S.
This is very useful. Thanks!