這是我的彈性搜索查詢的一部分:
{
"match": {
"value": {
"query": "1",
}
}
}
value 是我索引中的布爾欄位,在布爾欄位的搜索中,elasticsearch 是否接受 1 為真和 0 為假?
uj5u.com熱心網友回復:
如檔案ES 中指定的,接受true/"true"/false/"false"為布林值。
其他值,如0/1在最近的版本中會拋出錯誤
錯誤:創建查詢失敗:無法決議布林值1,預期為 [true] 或 [false]
注意:您應該使用術語查詢來過濾布爾欄位
uj5u.com熱心網友回復:
這很容易測驗...
首先創建索引:
PUT test
{
"mappings": {
"properties": {
"bool_field": {
"type": "boolean"
}
}
}
}
然后索引一個檔案:
PUT test/_doc/1
{
"bool_field": true
}
嘗試使用 0/1 而不是布林值進行查詢
POST test/_search
{
"query": {
"term": {
"bool_field": "1"
}
}
}
回復: Can't parse boolean value [1], expected [true] or [false]
{
"error" : {
"root_cause" : [
{
"type" : "query_shard_exception",
"reason" : "failed to create query: Can't parse boolean value [1], expected [true] or [false]",
"index_uuid" : "bZpN3j1kT9KtMBnGkpOmKQ",
"index" : "test"
}
],
"type" : "search_phase_execution_exception",
"reason" : "all shards failed",
"phase" : "query",
"grouped" : true,
"failed_shards" : [
{
"shard" : 0,
"index" : "test",
"node" : "CyVrqrOtR0CP3RfZtdBTag",
"reason" : {
"type" : "query_shard_exception",
"reason" : "failed to create query: Can't parse boolean value [1], expected [true] or [false]",
"index_uuid" : "bZpN3j1kT9KtMBnGkpOmKQ",
"index" : "test",
"caused_by" : {
"type" : "illegal_argument_exception",
"reason" : "Can't parse boolean value [1], expected [true] or [false]"
}
}
}
]
},
"status" : 400
}
PS:它曾經可以達到ES 5。從 ES 6 開始,布爾欄位只接受 true/false 值。
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/408444.html
標籤:
