弹性搜索设置索引"no"使用哪种类型,关键字还是文本?



弹性搜索设置"索引":"否",带有"索引":false 我们应该为"类型","关键字"或"文本"使用什么 会有什么区别吗?

因为由于该字段没有索引,我认为不会有任何区别?

index选项设置为在 Elasticsearch 2.x 中no或在 Elasticsearch> 5.x 中设置为false不会为该字段创建倒排索引,这意味着您无法对其执行搜索或过滤。但是,您可以通过使用 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.0n    }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.0n    }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
}

最新更新