我正在嘗試將 POST req 發送到 API,以便我只接收角色:“編輯器”的命中。未經過濾的回應如下所示:
_source: {
configuration: {
roles : [
{role : "lead"},
{role : "editor"},
]
}
}
我正在嘗試使用以下查詢來接收所需的回應:
body: {
size: 10,
query: {
bool: {
must: {
term: {
role : "editor"
}
}
}
}
}
但是即使我可以驗證有數千個帶有角色的點擊:“編輯器”,我也收到 0 個點擊。
我還嘗試了這個請求的變體:
body: {
size: 10,
query: {
bool: {
must: {
term: {
"roles.role" : "editor"
}
}
}
}
}
或者
body: {
size: 10,
query: {
bool: {
must: {
term: {
"roles" : "role.editor"
}
}
}
}
}
有誰知道我做錯了什么?問題似乎是角色是一個物件陣列,我沒有正確訪問角色值。
uj5u.com熱心網友回復:
如果您的欄位“角色”是嵌套型別,則必須使用嵌套查詢。
{
"query": {
"nested": {
"path": "roles",
"query": {
"term": {
"roles.role": {
"value": "editor"
}
}
}
}
}
}
如果不是“嵌套”,試試這個:
{
"query": {
"bool": {
"must": [
{
"term": {
"roles.role": {
"value": "lead"
}
}
}
]
}
}
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/504071.html
