elasticsearch Elasticsearch映射参数:已启用索引vs
我一直在努力使用两个elasticsearch映射参数:elasticsearch Elasticsearch映射参数:已启用索引vs,elasticsearch,indexing,mapping,elasticsearch,Indexing,Mapping,我一直在努力使用两个elasticsearch映射参数:索引和启用。我使用的是Elasticsearch 6.2.4 这是我的箱子 映射 PUT my_index { "mappings": { "_doc": { "properties": { "user_id": { "type": "keyword" }, "last_updated": { "type": "date"
索引
和启用
。我使用的是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"
}
索引编制
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"
}
Search1
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
Search2
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"
}
}
我阅读了关于上述选择的正式文件
最佳当设置
启用
为false时,您会告诉ES完全忽略对字段的解析,因此不会对其进行分析,也不会对其进行索引存储(当然,在\u source
字段中除外)
因此,ES甚至不知道该字段存在,因此,它处理这种情况就像您在查询任何其他不存在的字段一样,基本上就像源代码甚至不包含该字段一样。结果:ES不返回任何文档
当将
index
设置为false时,ES知道该字段存在(通过映射),但知道不应为其编制索引。因此,当您查询该字段时,ES会告诉您无法执行该操作,因为您已决定不为该字段编制索引。这就是为什么ES会抛出一个错误,因为您正在破坏您在映射中声明的契约。您是否希望会话\u data\u index\u false
上的查询不会出错,而只是不返回任何文档?@Val Nope。我只想了解两种选择之间的区别。基于官方文档,当我想要为特定字段值建立索引时,可以使用index和enabeld。但不确定何时使用每个选项,以及为什么一个选项会出错而另一个选项不会出错?哦,我看这已经足够清楚了。谢谢你的及时和恰当的回答。当然,很高兴它有帮助!