Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/facebook/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
<img src="//i.stack.imgur.com/RUiNP.png" height="16" width="18" alt="" class="sponsor tag img">elasticsearch 我可以将文本的默认类型定义为对象类型内的关键字吗?_<img Src="//i.stack.imgur.com/RUiNP.png" Height="16" Width="18" Alt="" Class="sponsor Tag Img">elasticsearch_Mapping_Elasticsearch 6 - Fatal编程技术网 elasticsearch 我可以将文本的默认类型定义为对象类型内的关键字吗?,elasticsearch,mapping,elasticsearch-6,elasticsearch,Mapping,Elasticsearch 6" /> elasticsearch 我可以将文本的默认类型定义为对象类型内的关键字吗?,elasticsearch,mapping,elasticsearch-6,elasticsearch,Mapping,Elasticsearch 6" />

elasticsearch 我可以将文本的默认类型定义为对象类型内的关键字吗?

elasticsearch 我可以将文本的默认类型定义为对象类型内的关键字吗?,elasticsearch,mapping,elasticsearch-6,elasticsearch,Mapping,Elasticsearch 6,假设我有以下映射: { "mappings": { "_doc": { "properties": { "id": {"type": "keyword"}, "params": { "type": "object", }, } } } } param

假设我有以下映射:

{
    "mappings": {
        "_doc": {
            "properties": {
                "id":       {"type": "keyword"},
                "params":   {
                    "type": "object",
                },
            }
        }
    }
}
params
有许多带有数字和文本值的字段。我不想指定它的所有字段,但我想指定所有文本字段都应该是
关键字
类型,而不是
文本
类型,这是默认值,并且经过分析(我希望避免)


我该怎么做?我正在使用ElasticSearch 6.7,这称为动态模板(请参阅)

对于您的问题,您可以如下定义映射:

PUT my_index
{
  "mappings": {
    "_doc": {
      "dynamic_templates": [
        {
          "strings": {
            "match_mapping_type": "string",
            "mapping": {
              "type": "keyword"
            }
          }
        }
      ]
    }
  }
}
这会将所有检测到的
字符串
字段转换为
关键字
。如果只想应用于字段的子集,可以使用
match
unmatch
path\u match
path\u unmatch
子句。(有关它们之间的差异,请参见文档)。

补充上述内容:

看来,这是可能的结合,以实现我想要的

PUT my_index
{
  "mappings": {
    "_doc": {
      "dynamic_templates": [
        {
          "keyword params": {
            "mapping": {
              "type": "keyword"
            },
            "match_mapping_type": "string",
            "path_match": "params.*"
          }
        }
      ]
    }
  }
}

您正在使用哪个版本的Elasticsearch?已更新。我用的是6.7谢谢!为了完整性,我添加了自己的答案,以按路径和类型(字符串)进行过滤。