[英]How to filter an array of objects based on values in an inner array with jq?
[英]How to filter Inner Objects in Elasticsearch?
我在Elasticsearch的文檔中有一個contacts
字段。 contacts
字段中的每個元素都是對象本身。 我想在contacts
字段上使用term
或terms
過濾器,以使其與contacts.province_id
為X
文檔匹配。 我已嘗試將contacts.province_id
用作搜索字段,但是它不起作用。 我應該如何過濾這些類型的字段?
"contacts":
[
{
"id": 1,
"address": "address1",
"tel": "40 07 13 22",
"doctor_id": 1,
"type_id": 1,
"lng": "51.374720",
"lat": "35.781986",
"city_id": 186,
"province_id": 8,
"hour_about": null,
"place_name": null
},
{
"id": 2,
"address": "address2",
"tel": null,
"doctor_id": 1,
"type_id": 2,
"lng": "51.520313",
"lat": "35.726983",
"city_id": 186,
"province_id": 8,
"hour_about": null,
"place_name": null
},
{
"id": 3,
"address": "address3",
"tel": null,
"doctor_id": 1,
"type_id": 2,
"lng": "51.456368",
"lat": "35.797505",
"city_id": 186,
"province_id": 8,
"hour_about": null,
"place_name": null
}
]
編輯:
我已經試過這個查詢:
GET /index_name/type_name/_search
{
"query": {
"filtered": {
"filter": {
"term": {
"contacts.province_id": 8
}
}
}
}
}
但它會返回3個結果,我希望有5個結果。 有什么問題?
謝謝你的幫助。
您使用了什么映射? 如果您使用的是嵌套類型,請嘗試使用嵌套過濾器 。
{
"filter": {
"nested": {
"path": "contacts",
"filter": {
"term": {
"contacts.province_id": 3
}
}
}
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.