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

时间:2019-02-03 15:42:51

标签: elasticsearch

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

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

1 个答案:

答案 0 :(得分:2)

在Elasticsearch 2.x中将index设置为no或在Elasticsearch> 5.x中将false设置为inverted index不会为该字段创建doc_values 对它执行搜索或过滤。但是您可以通过使用link在称为fielddata的数据上创建视图来进行排序和汇总,这是该字段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
}