你好 Elasticsearch 大师在那里。
给定以下索引和文档类型:localhost:9200/myindex/mydoctype
我目前有这个索引定义:
{
"myindex": {
"aliases": {},
"mappings": {
"mydoctype": {
"properties": {
"theNumber": {
"type": "integer"
},
"theString": {
"type": "string"
}
}
}
},
"settings": {
"index": {
"creation_date": "1487158714808",
"number_of_shards": "5",
"number_of_replicas": "1",
"version": {
"created": "1070599"
},
"uuid": "cm2OtivhTO-RjuZPeHvL1w"
}
},
"warmers": {}
}
}
Run Code Online (Sandbox Code Playgroud)
我能够添加这个文件:
{
"theNumber" : 0,
"theString" : "zero"
}
Run Code Online (Sandbox Code Playgroud)
但我没想到的是,我还可以添加此文档:
{
"theNumber" : 3.1418,
"theString" : 3,
"fiefoe" : "fiefoe"
}
Run Code Online (Sandbox Code Playgroud)
...字段类型不匹配的地方。以及引入了一个新的字段/列。由于我为索引定义的映射,我没想到会出现这种行为。
这是否与 Elasticsearch 无模式有关?是否可以将 Elasticsearch 设置为仅接受为该索引添加的每个文档的那些类型和字段?这就是elasticsearch映射首先的工作方式吗?(可能我不知道呵呵)
谢谢=)
Elasticsearch 使用动态映射,因此当它发现映射中不存在的字段时,它会尝试通过猜测其类型来对其进行索引。您可以dynamic: false在根对象的映射中使用什么来禁用此行为。在这种情况下,ElasticSearch 将忽略未映射的字段。
{
"myindex": {
"aliases": {},
"mappings": {
"mydoctype": {
"dynamic": false, <-----
"properties": {
"theNumber": {
"type": "integer"
},
"theString": {
"type": "string"
}
}
}
},
"settings": {
"index": {
"creation_date": "1487158714808",
"number_of_shards": "5",
"number_of_replicas": "1",
"version": {
"created": "1070599"
},
"uuid": "cm2OtivhTO-RjuZPeHvL1w"
}
},
"warmers": {}
}
}
Run Code Online (Sandbox Code Playgroud)
或者,dynamic:strict如果您想在未映射的字段尝试建立索引时抛出异常,则可以使用。
这方面的文档是here。
| 归档时间: |
|
| 查看次数: |
1228 次 |
| 最近记录: |