【问题标题】:Elasticsearch for setting index "no" which type to use, keyword or text?用于设置索引“否”的 Elasticsearch 使用哪种类型,关键字或文本?
【发布时间】:2019-02-13 21:49:02
【问题描述】:

Elasticsearch 用于设置 "index": "no", with "index": false 我们应该用什么来设置 "type", "keyword" OR "text" 会有什么区别吗?

因为该字段没有被索引,所以我认为不会有任何区别?

【问题讨论】:

    标签: elasticsearch


    【解决方案1】:

    在 Elasticsearch 2.x 中将 index 选项设置为 no 或在 Elasticsearch > 5.x 中设置为 false 不会为该字段创建 inverted index,这意味着您无法对其执行搜索或过滤。但是您可以通过使用doc_values 在名为fielddata 的数据上创建一个视图来进行排序和聚合,这是type 的字段重要之处。

    我使用text_or_keyword_field 创建了my_index,并通过将字段的type 设置为text 一次并在下一次设置为keyword 来运行搜索查询。

    PUT my_index
    {
      "mappings": {
        "_doc": {
          "properties": {
            "text_or_keyword_field": {
              "type": "keyword",
              "index": "false"
            }
          }
        }
      }
    }
    

    Elasticsearch 提出了 search_phase_execution_exception 并给出了预期的原因:

    {
      "error": {
        "root_cause": [
          {
            "type": "query_shard_exception",
            "reason": "failed to create query: {\n  \"match\" : {\n    \"text_or_keyword_field\" : {\n      \"query\" : \"brown fox\",\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": "hz4Vq6mPRaCc9HSxB-MEYg",
            "index": "my_index"
          }
        ],
        "type": "search_phase_execution_exception",
        "reason": "all shards failed",
        "phase": "query",
        "grouped": true,
        "failed_shards": [
          {
            "shard": 0,
            "index": "my_index",
            "node": "LvCoGAkyTbiVIeyF7UtXTw",
            "reason": {
              "type": "query_shard_exception",
              "reason": "failed to create query: {\n  \"match\" : {\n    \"text_or_keyword_field\" : {\n      \"query\" : \"brown fox\",\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": "hz4Vq6mPRaCc9HSxB-MEYg",
              "index": "my_index",
              "caused_by": {
                "type": "illegal_argument_exception",
                "reason": "Cannot search on field [text_or_keyword_field] since it is not indexed."
              }
            }
          }
        ]
      },
      "status": 400
    }
    

    【讨论】:

    • 您好,感谢您的回答,但很抱歉我没有正确理解您,所以您的意思是您尝试了两个映射,一个将“type”作为“keyword”,另一个将“type”作为“text”,接下来,当您对他们两个执行搜索查询时,您得到了上述错误?我对吗?另外,当我将该字段索引为“false”时,您为什么认为我会查询它,因为我将其索引为“false”,我不想查询它。我只是想知道当我将类型用作“关键字”和“文本”并将索引设置为“false”时是否会有任何区别,谢谢。
    • 感谢您的澄清。如果您不使用 doc_values,则没有区别。我已经编辑了答案并提供了进一步的解释。
    猜你喜欢
    • 2015-01-17
    • 2019-09-04
    • 1970-01-01
    • 1970-01-01
    • 2017-01-07
    • 2022-01-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多