你應該使用bool
查詢我試着用下面簡單的例子(動態映射):
POST my_index/my_type/
{
"name": "a",
"surname": "a",
"email": "[email protected]",
"custom_attributes": {
"custom1": "2bdwfwefgwef",
"custom2": "2015-08-03 00:43:00",
"custom3": "United States (English)"
},
"language": "US",
"gender": "m"
}
POST my_index/my_type/
{
"name": "b",
"email": "[email protected]",
"custom_attributes": {
"custom1": "2bdwfwefgwef",
"custom2": "2015-08-03 00:43:00",
"custom3": "United States (English)"
},
"language": "US",
"gender": "m"
}
POST my_index/my_type/
{
"surname": "c",
"email": "[email protected]",
"custom_attributes": {
"custom1": "2bdwfwefgwef",
"custom2": "2015-08-03 00:43:00",
"custom3": "United States (English)"
},
"language": "US",
"gender": "m"
}
POST my_index/my_type/
{
"email": "[email protected]",
"custom_attributes": {
"custom1": "2bdwfwefgwef",
"custom2": "2015-08-03 00:43:00",
"custom3": "United States (English)"
},
"language": "US",
"gender": "m"
}
GET my_index/_search
{
"from": 0,
"size": 10,
"query": {
"bool": {
"must_not": [
{
"exists": {
"field": "name"
}
},
{
"exists": {
"field": "surname"
}
}
]
}
}
}
導致:
{
"took": 51,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"failed": 0
},
"hits": {
"total": 1,
"max_score": 1,
"hits": [
{
"_index": "my_index",
"_type": "my_type",
"_id": "AVmfDTiBdjT9iO0jiYdN",
"_score": 1,
"_source": {
"email": "[email protected]",
"custom_attributes": {
"custom1": "2bdwfwefgwef",
"custom2": "2015-08-03 00:43:00",
"custom3": "United States (English)"
},
"language": "US",
"gender": "m"
}
}
]
}
}
你能提供一個結果的例子嗎?即使沒有將它映射爲嵌套,您也應該獲得子文檔。 – mayid
你能提供你使用的地圖嗎? – paweloque