【发布时间】:2015-07-12 00:43:17
【问题描述】:
我在 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 个结果。有什么问题?
感谢您的帮助。
【问题讨论】:
-
数组中的每个元素是不同的文档吗?
-
我认为它应该按照您的方式工作。我看到的唯一错误是您在查询数据时执行了 GET 而不是 POST。
标签: json search filter elasticsearch lucene