3 回答
TA贡献1893条经验 获得超10个赞
我不熟悉 elasticsearch-dsl(python),但以下搜索查询将为您提供所需的相同搜索结果:
SELECT ALL FROM Mytable WHERE field_1 NOT NULL and field_2 ="alpha"
在以下搜索查询的帮助下,搜索结果将是name="alpha"ANDcost字段not be null。您可以参考存在的查询以了解更多信息。
指数数据:
{ "name": "alpha","item": null }
{ "name": "beta","item": null }
{ "name": "alpha","item": 1 }
{ "name": "alpha","item": [] }
搜索查询:
您可以将 bool 查询与 exists 查询结合起来,如下所示:
{
"query": {
"bool": {
"must": [
{
"term": {
"name": "alpha"
}
},
{
"exists": {
"field": "item"
}
}
]
}
}
}
搜索结果:
"hits": [
{
"_index": "my-index",
"_type": "_doc",
"_id": "4",
"_score": 1.6931472,
"_source": {
"name": "alpha",
"item": 1
}
}
]
TA贡献1806条经验 获得超5个赞
你可以试试这个:
s = Mytable.search()
.query(Q('bool', must=[Q('match', field_2='alpha'), Q('exists', field='field_1')]))TA贡献1820条经验 获得超3个赞
query: {
bool: {
must: [
{
bool: {
must_not: {
missing: {
field: 'follower',
existence: true,
null_value: true,
},
},
},
},
{
nested: {
path: 'follower',
query: {
match: {
'follower.id': req.currentUser?.id,
},
},
},
},
],
},
},
添加回答
举报
