Elasticsearch DSL,在值列表中过滤对象列表
Elasticsearch DSL, filter list of objects with in list of values
我的数据是这样的:
[
{
"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 表示文档位置数组中的此处对象
类似于:
type_q = ElasticQ('bool', must=[
ElasticQ('match', type='opportunity'),
ElasticQ('terms', id=excluded_ids),
])
或者,如果您确实想排除 那些 ID:
type_q = ElasticQ('bool',
must=[ElasticQ('match', type='opportunity')]
must_not=[ElasticQ('terms', id=excluded_ids)]
)
我的数据是这样的:
[
{
"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 表示文档位置数组中的此处对象
类似于:
type_q = ElasticQ('bool', must=[
ElasticQ('match', type='opportunity'),
ElasticQ('terms', id=excluded_ids),
])
或者,如果您确实想排除 那些 ID:
type_q = ElasticQ('bool',
must=[ElasticQ('match', type='opportunity')]
must_not=[ElasticQ('terms', id=excluded_ids)]
)