<p>我使用您提供的文档体创建了一个新索引“testind”,并使用Postman REST客户端键入“testTyp”:</p>
<pre><code>POST http://localhost:9200/testind/testTyp
{
"id":"514d4e9f-09e7-4f13-b6c9-a0aa9b4f37a0",
"created":"2019-09-06 06:09:33.044433",
"meta":{
"userTags":[
{
"intensity":"1",
"sentiment":"0.84",
"keyword":"train"
},
{
"intensity":"1",
"sentiment":"-0.76",
"keyword":"amtrak"
}
]
}
}
</code></pre>
<p>当我查询索引的映射时,得到的是:</p>
<pre><code>GET http://localhost:9200/testind/testTyp/_mapping
{
"testind":{
"mappings":{
"testTyp":{
"properties":{
"created":{
"type":"text",
"fields":{
"keyword":{
"type":"keyword",
"ignore_above":256
}
}
},
"id":{
"type":"text",
"fields":{
"keyword":{
"type":"keyword",
"ignore_above":256
}
}
},
"meta":{
"properties":{
"userTags":{
"properties":{
"intensity":{
"type":"text",
"fields":{
"keyword":{
"type":"keyword",
"ignore_above":256
}
}
},
"keyword":{
"type":"text",
"fields":{
"keyword":{
"type":"keyword",
"ignore_above":256
}
}
},
"sentiment":{
"type":"text",
"fields":{
"keyword":{
"type":"keyword",
"ignore_above":256
}
}
}
}
}
}
}
}
}
}
}
}
</code></pre>
<p>正如您在映射中看到的,这些字段是映射的一部分,将来可以根据需要进行查询,因此,只要字段名不是这些中的一个-<a href="https://www.elastic.co/guide/en/elasticsearch/reference/6.4/sql-syntax-reserved.html" rel="nofollow noreferrer">https://www.elastic.co/guide/en/elasticsearch/reference/6.4/sql-syntax-reserved.html</a>(您可能希望避免使用术语“keyword”,因为在以后编写搜索查询时可能会混淆,因为字段名和类型都是相同的-“keyword”)。另外,请注意,映射是通过Elasticsearch中的动态映射(<a href="https://www.elastic.co/guide/en/elasticsearch/reference/6.3/dynamic-field-mapping.html#dynamic-field-mapping" rel="nofollow noreferrer">https://www.elastic.co/guide/en/elasticsearch/reference/6.3/dynamic-field-mapping.html#dynamic-field-mapping</a>)创建的,因此数据类型由Elasticsearch根据您拥有的值来确定提供。但是,这可能并不总是准确的,因此为了防止出现这种情况,可以使用PUT\u mapping API为索引定义自己的映射,然后防止出现新字段在类型中添加到映射。你知道吗</p>