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條經驗 獲得超2個贊
query: {
bool: {
must: [
{
bool: {
must_not: {
missing: {
field: 'follower',
existence: true,
null_value: true,
},
},
},
},
{
nested: {
path: 'follower',
query: {
match: {
'follower.id': req.currentUser?.id,
},
},
},
},
],
},
},
添加回答
舉報