如果我在文档中添加新的字符串字段,那么将自动创建它的映射,这里是字符串,这是好的:
curl -XPOST http://localhost:9200/jakis/typ -d '{"imie": "John"}'
结果:
{
"ok": true,
"_index": "jakis",
"_type": "typ",
"_id": "GY5AYdaVRH-Vg-XcBQzWYw",
"_version": 1
}
curl -XGET http://localhost:9200/jakis/_mapping
结果:
{
"jakis": {
"typ": {
"properties": {
"imie": {
"type": "string"
}
}
}
}
}
但是,如果我添加一个与映射中已存在的字段相同但不同类型的字段(在映射中它是字符串,这里我添加整数)然后Elasticsearch愉快地添加新文档但是整数字段的新映射不是放置在类型映射中:
curl -XPOST http://localhost:9200/jakis/typ -d '{"imie": 2}'
结果:
{
"ok": true,
"_index": "jakis",
"_type": "typ",
"_id": "zLpMl5_RSTiceFFG31mj6Q",
"_version": 1
}
curl -XGET http://localhost:9200/jakis/typ/_mapping
结果:
{
"typ": {
"properties": {
"imie": {
"type": "string"
}
}
}
}
问题是 - 将此字段添加为整数还是将其转换为字符串?有没有办法将其报告为错误?
答案 0 :(得分:1)
它会将数字2转换为字符串“2”。它抛出异常的唯一时间是没有合适的类型转换器或者什么时候它不能进行转换(例如将大整数添加到整数字段中)