【发布时间】:2022-01-08 10:26:09
【问题描述】:
我的数据如下所示:
[
{
"id": "00f0bbe514dcaf262c8a",
"status": "CL",
"type": "opportunity",
"locations": [
{
"name": "New York, USA",
"lat": 99.0853,
"lng": 99.7818,
"id": "456",
"type": "CI"
},
{
"name": "Boston, USA",
"lat": 80.0853,
"lng": 80.7818,
"id": "555",
"type": "CI"
},
{
"name": "London, UK",
"lat": 10.0853,
"lng": 10.7818,
"id": "999",
"type": "CI"
}
]
},
{
"id": "sadl9asod01",
"status": "CL",
"type": "opportunity",
"locations": [
{
"name": "Boston, USA",
"lat": 80.0853,
"lng": 80.7818,
"id": "555",
"type": "CI"
},
]
},
{
"id": "13094ulk",
"status": "CL",
"type": "project", # has right location but not type
"locations": [
{
"name": "Boston, USA",
"lat": 80.0853,
"lng": 80.7818,
"id": "555",
"type": "CI"
},
]
}
]
我想构建一个类型必须是机会的查询:
type_q = ElasticQ('bool', must=[ElasticQ('match', type='opportunity')])
query = self.index.search().query(type_q)
我知道如何使用 dsl 构建“in”查询,例如:
excluded_ids = self._excluded_jobs() # list
query = query.exclude('terms', id=excluded_ids)
但是,我怎样才能在 SQL 中添加我会这样的查询:
WHERE type='opportunity'
AND
location.id in (1, 2, 3)
- location 代表文档的locations数组中的here对象
【问题讨论】:
标签: python elasticsearch elasticsearch-dsl elasticsearch-dsl-py