我有一份檔案nested field:
testData.testDataId
我只想獲取具有testData.testDataIdas的檔案null
這是我的查詢:
{
"bool": {
"must_not": [
{ "exists": { "field": "testData.testDataId", "boost": 1.0 } }
],
"adjust_pure_negative": true,
"boost": 1.0
}
}
但是我也有那些“testData”為空的檔案。是否可以禁用?
例如:我有這 3 個檔案
[
{
"name": "test_user_1",
"additionalInfo": { "phoneNumber": "00000000", "address": "test_address" },
"testData": { "testDataId": "some_id", "description": "test_description" }
},
{
"name": "test_user_2",
"additionalInfo": { "phoneNumber": "00000000", "address": "test_address" },
"testData": { "description": "test_description" }
},
{
"name": "test_user_3",
"additionalInfo": { "phoneNumber": "00000000", "address": "test_address" }
}
]
我只想找回test_user_2
uj5u.com熱心網友回復:
特長;
由于您正在處理nested field您需要使用嵌套查詢。
修理
GET /72491619/_search
{
"query": {
"nested": {
"path": "testData",
"query": {
"bool": {
"must_not": [
{
"exists": {
"field": "testData.testDataId"
}
}
]
}
}
}
}
}
重現
為了設定索引和資料,我使用了下面的 api 呼叫:
PUT /72491619/
{
"mappings": {
"properties": {
"name": {
"type": "keyword"
},
"additionalInfo":{
"type": "nested",
"properties": {
"phoneNumber": {
"type": "keyword"
},
"address": {
"type": "keyword"
}
}
},
"testData":{
"type": "nested",
"properties": {
"testDataId": {
"type": "keyword"
},
"description": {
"type": "keyword"
}
}
}
}
}
}
POST /_bulk
{"index":{"_index":"72491619"}}
{"name":"test_user_1","additionalInfo":{"phoneNumber":"00000000","address":"test_address"},"testData":{"testDataId":"some_id","description":"test_description"}}
{"index":{"_index":"72491619"}}
{"name":"test_user_2","additionalInfo":{"phoneNumber":"00000000","address":"test_address"},"testData":{"description":"test_description"}}
{"index":{"_index":"72491619"}}
{"name":"test_user_3","additionalInfo":{"phoneNumber":"00000000","address":"test_address"}}
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/485982.html
