簡體   English   中英

如何在Elasticsearch中過濾內部對象?

[英]How to filter Inner Objects in Elasticsearch?

我在Elasticsearch的文檔中有一個contacts字段。 contacts字段中的每個元素都是對象本身。 我想在contacts字段上使用termterms過濾器,以使其與contacts.province_idX文檔匹配。 我已嘗試將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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM