![](/img/trans.png)
[英]Elasticsearch : Root mapping definition has unsupported parameters index : not_analyzed
[英]Elasticsearch mapping parameters : index vs enabled
我一直在努力使用兩個Elasticsearch映射參數: index
和enabled
。 我正在使用Elasticsearch 6.2.4。
這是我的情況。
制圖
PUT my_index
{
"mappings": {
"_doc": {
"properties": {
"user_id": {
"type": "keyword"
},
"last_updated": {
"type": "date"
},
"session_data_index_false": {
"index" : false,
"type" : "keyword"
},
"session_data_enabled_false": {
"enabled" : false
}
}
}
}
}
索引編制
PUT my_index/_doc/1
{
"user_id": "jpountz",
"session_data_index_false": "hello",
"session_data_enabled_false": "hello",
"last_updated": "2015-12-06T18:22:13"
}
搜索1
GET my_index/_search
{
"query": {
"match": {
"session_data_index_false": "hello"
}
}
}
我收到以下消息時出現400錯誤。
{
"error": {
"root_cause": [
{
"type": "query_shard_exception",
"reason": "failed to create query: {\n \"match\" : {\n \"session_data_index_false\" : {\n \"query\" : \"hello\",\n \"operator\" : \"OR\",\n \"prefix_length\" : 0,\n \"max_expansions\" : 50,\n \"fuzzy_transpositions\" : true,\n \"lenient\" : false,\n \"zero_terms_query\" : \"NONE\",\n \"auto_generate_synonyms_phrase_query\" : true,\n \"boost\" : 1.0\n }\n }\n}",
"index_uuid": "6ByxNrjIRQmF23zcmKOvUA",
"index": "my_index"
}
],
"type": "search_phase_execution_exception",
"reason": "all shards failed",
"phase": "query",
"grouped": true,
"failed_shards": [
{
"shard": 0,
"index": "my_index",
"node": "DYPnEJWjTtm58oxZ9F-RSg",
"reason": {
"type": "query_shard_exception",
"reason": "failed to create query: {\n \"match\" : {\n \"session_data_index_false\" : {\n \"query\" : \"hello\",\n \"operator\" : \"OR\",\n \"prefix_length\" : 0,\n \"max_expansions\" : 50,\n \"fuzzy_transpositions\" : true,\n \"lenient\" : false,\n \"zero_terms_query\" : \"NONE\",\n \"auto_generate_synonyms_phrase_query\" : true,\n \"boost\" : 1.0\n }\n }\n}",
"index_uuid": "6ByxNrjIRQmF23zcmKOvUA",
"index": "my_index",
"caused_by": {
"type": "illegal_argument_exception",
"reason": "Cannot search on field [session_data_index_false] since it is not indexed."
}
}
}
]
},
"status": 400
搜索2
GET my_index/_search
{
"query": {
"match": {
"session_data_enabled_false": "hello"
}
}
}
在這種情況下,我沒有收到任何錯誤。 相反,我得到了以下結果,這意味着未找到任何文檔。
{
"took": 1,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"skipped": 0,
"failed": 0
},
"hits": {
"total": 0,
"max_score": null,
"hits": []
}
}
恢復
GET my_index/_doc/1
當然,我可以檢索原始數據。
{
"_index": "my_index",
"_type": "_doc",
"_id": "1",
"_version": 1,
"found": true,
"_source": {
"user_id": "jpountz",
"session_data_index_false": "hello",
"session_data_enabled_false": "hello",
"last_updated": "2015-12-06T18:22:13"
}
}
我閱讀了上述選項的正式文檔。
而且,我已經閱讀了這篇文章,但發現它與elasticsearch 1.5兼容。
這里有人知道這兩個選項有何不同嗎?
提前致謝。
最好
如果將設置enabled
為false,則告訴ES完全忽略該字段的分析,因此既不會對其進行分析,也不會對其進行索引(當然不在_source
字段中)。
因此,ES甚至都不知道該字段存在,因此,它會像對待其他任何不存在的字段一樣處理該情況,基本上就像源甚至不包含該字段一樣。 結果:ES不返回任何文檔。
將index
設置為false時,ES會知道該字段存在(通過映射),但是它知道不應對該字段進行索引。 因此,當您對其查詢時,ES會告訴您您無法執行此操作,因為您已決定不對該字段進行索引。 這就是ES拋出錯誤的原因,因為您違反了在映射中聲明的合同。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.