elasticsearch - Elasticsearch用于设置索引 “no”使用哪种类型,关键字还是文本?

标签 elasticsearch

Elasticsearch设置“index”:“no”,以“index”:false设置“type”,“keyword”或“text”应该使用什么?

因为因为该字段未编制索引,所以我认为不会有任何区别吗?

最佳答案

在Elasticsearch 2.x中将index选项设置为no或在Elasticsearch> 5.x中将false设置为该字段不会创建inverted index,这意味着您无法对其进行搜索或过滤。但是您可以通过使用doc_values 在名为fielddata的数据上创建 View 来进行排序和聚合,这是该字段的type至关重要的地方。我使用my_index创建了text_or_keyword_field,并通过将字段的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
}

关于elasticsearch - Elasticsearch用于设置索引 “no”使用哪种类型,关键字还是文本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54504550/

相关文章:

mongodb - Elasticsearch River(mongodb),建模架构

ruby-on-rails - 在digitalocean上运行elasticsearch

elasticsearch - 无法为带有错误消息的索引创建映射设置

elasticsearch - 超过 SwifType 速率限制

elasticsearch - 聚合问题(数字四舍五入?)

docker - 使用 Docker 镜像的神秘 Filebeat 7 X-Pack 问题

sql-server - 删除文档中的重复记录(Elasticsearch)

Elasticsearch:多个带有快速矢量荧光笔的 pre_tags/post_tags

elasticsearch - 在 FreeBSD 中安装 Elasticsearch metricbeat

java - Elasticsearch 评分精度