Elasticsearch Java API MoreLikeThis 与“_search”休息端点相比不返回文档

Elasticsearch Java API MoreLikeThis not returning documents compared to "_search" rest endpoint

意向: Elasticsearch Java Java 中的 MoreLikeThis 查询完全按照 more_like_this 通过 /_search 其余端点过滤的原始查询执行的操作。

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"
  ]
}

这是我对上述内容的 Java 实现:

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);

但是,结果与 more_like_this 返回的 rest 端点大不相同。我在索引中得到了大约 4/5 的整个文档的匹配项。好像正在应用 none 个过滤器

针对 ES v1.4.2v1.6.2

任何建议please.Thanks

我用 QueryBuilders.moreLikeThisQuery() 得到了想要的结果。 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()

备注:

  • QueryBuilders 在与 ES v2.0 和 beyound
  • 的兼容性方面似乎是前进的方向
  • @MoreLikeThisRequestBuilder 将在 ES v1.6 + 中弃用并在 2.0
  • 中删除