简体   繁体   English

使用elastic4s返回嵌套字段

[英]return nested fields using elastic4s

I have data stored with a nested location object and can't figure out how to get elastic4s to return the location as part of the result of a search. 我将数据存储在一个嵌套的位置对象中,并且无法弄清楚如何获取elastic4s作为搜索结果的一部分返回该位置。 I have data that when queried (from the REST endpoint) looks like this: 我有从REST端点查询时的数据看起来像这样:

{
    "_index": "us_large_cities",
    "_type": "city",
    "_id": "AU7ke-xU_N_KRYZ5Iii_",
    "_score": 1,
    "_source": {
        "city": "Oakland",
        "state": "CA",
        "location": {
            "lat": "37.8043722",
            "lon": "-122.2708026"
        }
    }
}

When I try querying it using elastic4s like so: 当我尝试使用elastic4s进行查询时,如下所示:

search in "us_large_cities"->"city" fields("location", "city", ) query {
filteredQuery filter {
  geoPolygon("location") point(37.9, -122.31) point(37.8, -122.31) point(37.8, -122.25) point(37.9, -122.25)
}

I get back results like this: 我得到这样的结果:

{
  "_index" : "us_large_cities",
  "_type" : "city",
  "_id" : "AU7keH9l_N_KRYZ5Iig0",
  "_score" : 1.0,
  "fields" : {
    "city" : [ "Berkeley" ]
  }
}

Where I would expect to see "location" but don't. 我希望看到“位置”但没有看到的位置。 Does anyone know how I specify the fields so that I can actually get the location? 有谁知道我如何指定字段,以便我可以实际获得位置?

You should try using source filtering instead, as shown below. 您应该尝试改用源过滤 ,如下所示。 Note the use of sourceInclude instead of fields . 注意使用sourceInclude而不是fields

search in "us_large_cities"->"city" sourceInclude("location", "city") query {
filteredQuery filter {
  geoPolygon("location") point(37.9, -122.31) point(37.8, -122.31) point(37.8, -122.25) point(37.9, -122.25)
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM