eLasticsearch在保存时将Java地图内部的字段类型从字符串转换为日期
我有以下索引映射 - 一个称为customfields
的字段包含其他字段,例如firstName
,lastName
等
{
"customFields": {
"properties": {
"firstName": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"lastName": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"address": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"dateOfBirth": {
"type": "date"
},
}
}
}
。 > customfields 是map<字符串,对象>
。
dateofbirth
字段接受yyyy-mm-dd
格式中的值,并且是string
。
但是,当将其保存在Elasticsearch上时,类型将变为date
。我一直在调试,在应用程序中没有找到dateofbirth
键入到达Elasticsearch之前的更改。
Elasticsearch是否可能在后台更改类型?
I have the following index mapping - a field called customFields
contains other fields such as firstName
, lastName
, etc.
{
"customFields": {
"properties": {
"firstName": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"lastName": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"address": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"dateOfBirth": {
"type": "date"
},
}
}
}
In my Spring project, customFields
is a Map<String, Object>
.
The dateOfBirth
field accepts values in the YYYY-MM-DD
format and is a String
.
However, when its being saved on ElasticSearch, the type becomes date
. I have been debugging and I haven't found anywhere in the application where the dateOfBirth
type changes to date before being sent to ElasticSearch.
Is it possible ElasticSearch changes the type by itself in the background?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您没有明确定义这些字段的Elasticsearch映射,并且当Elasticsearch看到它们时,它试图将它们与最佳数据类型匹配,因为您的
dateofbirth
具有yyyy-mm-dd 即使它在“”中包含它,并且您希望它们为
text
字段,弹性搜索将其映射到date
由于其值而导致的字段。如果要避免这种情况,则需要在您的Elasticsearch索引映射中使用
Text
数据类型来定义dateofbirth
。希望这会有所帮助。
You are not defining the Elasticsearch mapping explicitly for these fields, and when Elasticsearch see them it tries to match them with best data types, as your
dateOfBirth
is having aYYYY-MM-DD
even if its enclosed in "" and you want them to be atext
field, Elasticsearch maps it todate
field due to its value.if you want to avoid this, you need to define
dateOfBirth
explicitly withtext
data type in your Elasticsearch index mapping.Hope this helps.