在spring引导应用程序中,当将对象索引到es中时,我会得到以下异常。
Suppressed: org.elasticsearch.client.ResponseException: method [PUT], host [http://localhost:9299],
URI [/my_index_name/_doc/1000001_000000004-v2?timeout=5s], status line [HTTP/1.1 400 Bad Request]
{"error":{"root_cause":[{"type":"mapper_parsing_exception","reason":"failed to parse field [billingperiod]
of type [keyword] in document with id '1000001_000000004-v2'. Preview of field's value:
'{enddate=2016-12-31, startdate=2016-10-01}'"}],"type":"mapper_parsing_exception","reason":"failed to
parse field [billingperiod] of type [keyword] in document with id '1000001_000000004-v2'. Preview of
field's value: '{enddate=2016-12-31, startdate=2016-10-01}'","caused_by":{"type":"illegal_state_exception",
"reason":"Can't get text on a START_OBJECT at 1:399"}},"status":400}
at org.elasticsearch.client.RestClient.convertResponse(RestClient.java:318)
at org.elasticsearch.client.RestClient.performRequest(RestClient.java:288)
at org.elasticsearch.client.RestClient.performRequest(RestClient.java:262)
at org.elasticsearch.client.RestHighLevelClient.internalPerformRequest(RestHighLevelClient.java:1628)
... 133 common frames omitted
Caused by: org.elasticsearch.ElasticsearchException:
Elasticsearch exception [type=illegal_state_exception, reason=Can't get text on a START_OBJECT at 1:399]
at org.elasticsearch.ElasticsearchException.innerFromXContent(ElasticsearchException.java:496)
at org.elasticsearch.ElasticsearchException.fromXContent(ElasticsearchException.java:407)
at org.elasticsearch.ElasticsearchException.innerFromXContent(ElasticsearchException.java:437)
at org.elasticsearch.ElasticsearchException.failureFromXContent(ElasticsearchException.java:603)
at org.elasticsearch.rest.BytesRestResponse.errorFromXContent(BytesRestResponse.java:179)
... 136 common frames omitted
该类有两个静态字段和两个LocalDate
类型的实例变量以及一个视图方法,其中一个是重写的toString。
映射如下。没有映射,索引工作得很好。但是,需要配置null_value,因为对象可以为null。
{
"dynamic_templates": [
{
"mapStringToKeywordByDefault": {
"match_mapping_type": "string",
"mapping": {
"type": "keyword"
}
}
}
],
"properties": {
"billingperiod": {
"type": "keyword",
"null_value": "anemptystring"
}
}
}
然而,我试图用keyword
替换flattened
状态:“一个字符串值,它替代了扁平对象字段中的任何显式空值。默认为null,这意味着空值被视为丢失。”因此,如果对象本身是空的,那么它就不能工作。
版本ElasticSearch 7.10 (不能更改)
我犯了什么错?我能做些什么才能让它发挥作用?
对ilvar:的答复进行更新
使用示例的配置,可以创建索引,但找不到空值。它需要null_value
的映射。但是,如果不指定记帐期的类型,则会失败:
"billingperiod": {
"properties": {
"startdate": {"type": "date"},
"enddate": {"type": "date"}
},
"null_value": "anothertry"
}
原因: org.elasticsearch.ElasticsearchException: Elasticsearch异常[type=mapper_parsing_exception,reason=Mapping对票据周期的定义不支持参数: null_value : anothertry]
对于flattened
类型,它也会失败,这在我看来并不清楚,因为没有type
和null_value
,它就能工作。
"billingperiod": {
"type": "flattened",
"properties": {
"startdate": {"type": "date"},
"enddate": {"type": "date"}
},
"null_value": "anothertry"
}
由: org.elasticsearch.ElasticsearchException: Elasticsearch异常引起的[type=mapper_parsing_exception,reason=Mapping对票据周期的定义不支持参数:属性:{enddate={type=date},startdate={type=date}]]
下面的映射可以工作,但不允许票据周期本身的空项,而只允许在其中的字段(例如,{startdate=2000-01-01,enddate=null}被找到,但null本身不允许)。
"billingperiod": {
"type": "flattened",
"null_value": "anothertry"
}
发布于 2022-02-02 21:39:14
您的映射应该正确地反映您的数据模式,因此您应该有如下内容:
"billingperiod": {
"properties": {
"startdate": {"type": "date"},
"enddate": {"type": "date"}
}
}
https://stackoverflow.com/questions/70958144
复制相似问题