问题
我是弹性搜索的新手,我想了解动态映射和重新索引文档之间的关系。
根据我在启用动态映射时的实验,文档的重新索引是自动完成的。这意味着如果您向文档添加一个新字段,它会自动编入索引。
另一方面,如果索引没有开启动态映射,新的映射将不会被索引并且必须执行手动重新索引。其他文件将不会在搜索中找到。
这是一个正确的假设吗。我试图找出有关此的明确信息,但找不到。
你可以在下面找到我的实验
TEST1 - 带映射的索引
# 1.1 create index with mapping dynamic
PUT /product_dyn_on
{
"mappings" : {
"dynamic": true,
"properties": {
"price": { "type": "integer" }
}
}
}
# 1.2 create a document
POST /product_dyn_on/_doc/1
{ "price": 100 }
# 1.3 create a document with a field that was not mapped at the beginning
POST /product_dyn_on/_doc/2
{ "price": 100, "discount" : 20}
# 1.4 browse document to see if it has was mapped
GET /product_dyn_on/_search
GET /product_dyn_on/_search
{
"query": {"term" : {"discount" : 20}}
}
GET /product_dyn_on/_search
{
"query": {"match" : {"price" : 100}}
}
# 1.5 - update first object
PUT /product_dyn_on/_doc/1
{
"price" : 200,
"discount" : 20
}
# 1.6 - check results (both objects are returned)
GET /product_dyn_on/_search
{
"query": {"match" : {"discount" : 20}}
}
TEST2 - 没有映射的索引
# 2.1 create index with mapping dynamic
PUT /product_dyn_off
{
"mappings" : {
"dynamic": false,
"properties": {
"price": { "type": "integer" },
"is_active": {"type": "boolean" },
"price": { "type": "integer"},
"sold": { "type": "long"}
}
}
}
# 2.2 create a document
POST /product_dyn_off/_doc/1
{ "price": 100 }
# 2.3 create a document with a field that was not mapped at the beginning
POST /product_dyn_off/_doc/2
{ "price": 100, "discount" : 20}
# 2.4 browse document to see if it has was mapped
GET /product_dyn_off/_search
GET /product_dyn_off/_search
{
"query": {"term" : {"discount" : 20}}
}
GET /product_dyn_off/_search
{
"query": {"match" : {"price" : 100}}
}
# 2.5 - Update first object
PUT /product_dyn_off/_doc/1
{
"price" : 200,
"discount" : 20
}
# 2.6 - Check results
GET /product_dyn_off/_search
GET /product_dyn_off/_search
{
"query": {"match" : {"discount" : 20}}
}
GET /product_dyn_off/_search
{
"query": {"match" : {"price" : 200}}
}
# Clean Everything
DELETE /product_dyn_on
DELETE /product_dyn_off