简体   繁体   English

Elasticsearch映射参数:索引与启用

[英]Elasticsearch mapping parameters : index vs enabled

I've been struggling with two elasticsearch mapping parameters: index and enabled . 我一直在努力使用两个Elasticsearch映射参数: indexenabled I'm using Elasticsearch 6.2.4. 我正在使用Elasticsearch 6.2.4。


Here's my case. 这是我的情况。

Mapping 制图

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
        }
      }
    }
  }
}

Indexing 索引编制

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 搜索1

GET my_index/_search
{
  "query": {
    "match": {
      "session_data_index_false": "hello"
    }
  }
}

I got 400 error with following message. 我收到以下消息时出现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 搜索2

GET my_index/_search
{
  "query": {
    "match": {
      "session_data_enabled_false": "hello"
    }
  }
}

In this case, I didn't get any error. 在这种情况下,我没有收到任何错误。 Instead, I got following result, meaning that none of documents was found. 相反,我得到了以下结果,这意味着未找到任何文档。

{
  "took": 1,
  "timed_out": false,
  "_shards": {
    "total": 5,
    "successful": 5,
    "skipped": 0,
    "failed": 0
  },
  "hits": {
    "total": 0,
    "max_score": null,
    "hits": []
  }
}

Retrieval 恢复

GET my_index/_doc/1

Of course, I could retrieve original data. 当然,我可以检索原始数据。

{
  "_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"
  }
}

I read official documents on above options. 我阅读了上述选项的正式文档。

And also, I've read this article but found out that it was compatible with elasticsearch 1.5. 而且,我已经阅读了这篇文章,但发现它与elasticsearch 1.5兼容。

Is anyone here aware of how those two options differ from each other? 这里有人知道这两个选项有何不同吗?

Thanks in advance. 提前致谢。

Best 最好

When settings enabled to false, you tell ES to completely ignore the parsing of the field, so it will neither be analyzed, nor indexed not stored (except in he _source field of course). 如果将设置enabled为false,则告诉ES完全忽略该字段的分析,因此既不会对其进行分析,也不会对其进行索引(当然不在_source字段中)。

So, ES is not even aware that the field exists, and thus, it handles that case as if you were querying on any other non-existent field, basically as if the source didn't even contain the field. 因此,ES甚至都不知道该字段存在,因此,它会像对待其他任何不存在的字段一样处理该情况,基本上就像源甚至不包含该字段一样。 Result: ES doesn't return any document. 结果:ES不返回任何文档。

When setting index to false, ES is aware that the field exists (via the mapping), but it knows that it shouldn't be indexed. index设置为false时,ES会知道该字段存在(通过映射),但是它知道不应对该字段进行索引。 So when you query on it, ES tells you that you cannot do it since you've decided not to index that field. 因此,当您对其查询时,ES会告诉您您无法执行此操作,因为您已决定不对该字段进行索引。 That's why ES throws an error since you're breaking the contract that you've declared in your mapping. 这就是ES抛出错误的原因,因为您违反了在映射中声明的合同。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM