ES版本:6.4.3
首先,請想象我有一個這樣的索引:
- 創建一個新索引“test_1”,
- 存盤一些資料,
#### 1.create a new index "test_1"
DELETE test_1
PUT /test_1/
{
"settings": {
"number_of_shards": 1
},
"mappings": {
"_doc": {
"properties": {
"title": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
}
}
}
}
}
GET /test_1/_mapping
GET /test_1/_refresh
GET /test_1/_search
#### 2.put some doc
POST _bulk
{ "index" : { "_index" : "test_1", "_id" : "100" } }
{ "title" : ["100","101"] }
{ "index" : { "_index" : "test_1", "_id" : "101" } }
{ "title" : "100" }
- 測驗集
#### 3.test agg
GET /test_1/_search
{
"size": 0,
"aggs": {
"title": {
"terms": {
"field": "title.keyword",
"size": 100
}
}
}
}
它按預期作業,結果如下:
{
"took": 3,
"timed_out": false,
"_shards": {
"total": 1,
"successful": 1,
"skipped": 0,
"failed": 0
},
"hits": {
"total": 2,
"max_score": 0,
"hits": []
},
"aggregations": {
"title": {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 0,
"buckets": [
{
"key": "100",
"doc_count": 2
},
{
"key": "101",
"doc_count": 1
}
]
}
}
}
- 測驗崩潰
#### 4. test collapse
GET /test_1/_search
{
"_source": false,
"from":0,
"size": 10,
"query": {
"match_all": {
}
},
"collapse": {
"field": "title.keyword",
"inner_hits": {
"name": "latest",
"size": 1
}
}
}
結果是一個錯誤:
{
"error": {
"root_cause": [
{
"type": "illegal_state_exception",
"reason": "failed to collapse 0, the collapse field must be single valued"
}
],
"type": "search_phase_execution_exception",
"reason": "all shards failed",
"phase": "query",
"grouped": true,
"failed_shards": [
{
"shard": 0,
"index": "test_1",
"node": "1TlabepgQSi-5WvjVm6MuQ",
"reason": {
"type": "illegal_state_exception",
"reason": "failed to collapse 0, the collapse field must be single valued"
}
}
],
"caused_by": {
"type": "illegal_state_exception",
"reason": "failed to collapse 0, the collapse field must be single valued",
"caused_by": {
"type": "illegal_state_exception",
"reason": "failed to collapse 0, the collapse field must be single valued"
}
}
},
"status": 500
}
所以我的問題是為什么會報錯,是不是和es關于collapse的這個描述有關:
The field used for collapsing must be a single valued keyword or numeric field with doc_values activated.
如果兩者相關,為什么錯誤的原因是failed to collapse 0,這個0來自哪里?真誠感謝任何答案。
uj5u.com熱心網友回復:
首先,感謝您提供可重復的示例,這很有幫助!
然后,關于崩潰,確實,它只適用于單值欄位。在您的第一個檔案中,title是一個陣列,因此是多值的,不適合折疊。
簡單地說,0您在錯誤訊息中看到的是內部檔案 ID,即它是每個檔案在被索引時獲取的增量編號。在您的情況下, 0 代表已編入索引的第一個檔案。如果您在批量呼叫中反轉檔案,您會看到1相反的資訊。
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/414396.html
標籤:
