ElasticSearch DSL -> 组合多个过滤器并消除元数据
ElasticSearch DSL -> Combine multiple filters and eliminate metadata
以下查询假设 return product_id 为 12 的文档。
request = Search(using=client, index='myIndex') \
.filter("match",product_id=12) \
.source(myFieldsArray)
现在我还想删除所有 parent
为空的文档。
我还希望元数据不被 returned,只有实际数据(在 kopf 上我在查询字符串上使用 filter_path=hits.hits._source.*
)
如何在 elastic search-dsl 上执行这些操作?
详情:使用 Elasticsearch 2.4
假设 parent
是一个文档字段,而元数据是指 _source
。对于第一个条件
cut out all documents where parent
is null
您必须在 must_not
子句中使用 exists query。对于
metadata not be returned
你必须设置"_source": false
查询翻译如下:
{
"query": {
"bool": {
"filter": [
{
"term": {
"product_id": 12
}
},
{
"bool": {
"must_not": {
"exists": {
"field": "parent"
}
}
}
}
]
}
},
"_source": false
}
过滤器可以链接起来,就在 .filter(
之外。为了消除元数据,您必须将 params
设置为 .params(filter_path="hits.hits._source.*")
以下查询假设 return product_id 为 12 的文档。
request = Search(using=client, index='myIndex') \
.filter("match",product_id=12) \
.source(myFieldsArray)
现在我还想删除所有 parent
为空的文档。
我还希望元数据不被 returned,只有实际数据(在 kopf 上我在查询字符串上使用 filter_path=hits.hits._source.*
)
如何在 elastic search-dsl 上执行这些操作?
详情:使用 Elasticsearch 2.4
假设 parent
是一个文档字段,而元数据是指 _source
。对于第一个条件
cut out all documents where
parent
is null
您必须在 must_not
子句中使用 exists query。对于
metadata not be returned
你必须设置"_source": false
查询翻译如下:
{
"query": {
"bool": {
"filter": [
{
"term": {
"product_id": 12
}
},
{
"bool": {
"must_not": {
"exists": {
"field": "parent"
}
}
}
}
]
}
},
"_source": false
}
过滤器可以链接起来,就在 .filter(
之外。为了消除元数据,您必须将 params
设置为 .params(filter_path="hits.hits._source.*")