0
我正在使用elasticsearch 5.5.0。如何查詢對象數組作爲術語查詢的一部分
林我的索引我有彈性的樣子了JSON類型吸附部的數據:
"directions": "Exit the M4 at Junction 1",
"phoneNumber": "03333212001",
"website": "https://www.londoneye.com/",
"postCode": "SE1 7PB",
"categories": [
{
"id": "ce4cf4d0-6ddd-49fd-a8fe-3cbf7be9b61d",
"name": "Theater"
},
{
"id": "5fa1a3ce-fd5f-450f-92b7-2be6e3d0df90",
"name": "Family"
},
{
"id": "ed492986-b8a7-43c3-be3d-b17c4055bfa0",
"name": "Outdoors"
}
],
"genres": [],
"featuredImage": "https://www.daysoutguide.co.uk/media/1234/london-eye.jpg",
"images": [],
"region": "London",
我的下一個查詢看起來像:
var query2 = Query<Attraction>.Bool(
bq => bq.Filter(
fq => fq.Terms(t => t.Field(f => f.Region).Terms(request.Region.ToLower())),
fq => fq.Terms(t => t.Field(f => f.Categories).Terms(request.Category.ToLower())))
查詢生成的樣子:
{
"query": {
"bool": {
"filter": [
{
"terms": {
"region": [
"london"
]
}
},
{
"terms": {
"categories": [
"family"
]
}
}
]
}
}
}
不返回結果。如果我拿出類別我得到的結果。所以我試圖對類別是對象數組進行術語篩選。看起來我正在做這個查詢錯誤。任何有關如何使這個工作的提示?
問候
伊斯梅爾
我想你想指定字段的完整路徑:'categories.name'。這應該工作。 – Slomo
你應該使用嵌套查詢,你會發現在[文檔](https://www.elastic.co/guide/en/elasticsearch/client/net-api/5.x/nested-query-usage.html) 。 – Rob
搶劫,不知道你如何與Nest客戶端做到這一點?我知道如何處理DSL – Ismail