Java API for distance_feature 在 Elastic Search 中

Java API for distance_feature in Elastic Search

我正在尝试使用弹性搜索实现日期和地理位置字段的相关性提升 distance_feature。 Java API 对应什么 distance_feature 查询?

以下查询在 Kibana 上运行良好:

{
  "query": {
    "bool": {
      "should": [
        {
          "multi_match": {
            "query": "mountain",
            "fields": [
              "description$string"
            ]
          }
        },
        {
          "bool": {
            "should": [
              {
                "distance_feature": {
                  "field": "location$location",
                  "pivot": "1km",
                  "origin": [
                    -35.58,20.4
                  ],
                  "boost": 1
                }
              },
              {
                "distance_feature": {
                  "field": "date_established$date",
                  "pivot": "10d",
                  "origin": "now",
                  "boost": 10
                }
              }
            ]
          }
        }
      ]
    }
  },
  "_source": {
    "includes": [
      "title$string",
      "location$location",
      "date_established$date"
    ]
  }
}```

I do not want to use the decay function for this case.

您可以使用 DistanceFeatureQueryBuilder class:

对于地理点:

GeoPoint geo = new GeoPoint(-35.58, 20.4);
DistanceFeatureQueryBuilder.Origin origin = new DistanceFeatureQueryBuilder.Origin(geo);
DistanceFeatureQueryBuilder dfqb = new DistanceFeatureQueryBuilder("location$location", origin, "1km")

日期:

Origin origin = new Origin("now");
DistanceFeatureQueryBuilder dfqb = new DistanceFeatureQueryBuilder("date_established$date", origin, "10d")

filed an issue 请求在 QueryBuilders 中为 distance_feature 添加工厂方法。