我试图使用注释更改实体中字段的名称
@JsonNaming(PropertyNamingStrategy.UpperCamelCaseStrategy.class)
和
@JsonProperty()
对于嵌套字段,但这不适用于嵌套字段,例如:
实体集:
@JsonNaming(PropertyNamingStrategy.UpperCamelCaseStrategy.class)
public class TaxMapKey {
private String parcelNumber;
private String ownershipType;
@JsonProperty("TransferList")
@Field(type = FieldType.Nested, includeInParent = true)
private Set<Transfer> transferList = new HashSet<>();
}
@JsonNaming(PropertyNamingStrategy.UpperCamelCaseStrategy.class)
public class Transfer {
private Long transferId;
private String documentNumber;
@JsonProperty("Grantor")
@Field(type = FieldType.Nested)
private Grantor grantor;
}
@JsonNaming(PropertyNamingStrategy.UpperCamelCaseStrategy.class)
public class Grantor {
private Long grantorId;
private String documentNumber;
private Integer price;
private String instrumentType;
}
当我使用这样的查询从该实体请求数据时:
curl -X GET \
http://localhost:9200/search_tax_map_key/_search \
-H 'Content-Type: application/json' \
-d '{
"_source": ["TransferList.Grantor.Price", "TransferList.Grantor.InstrumentType"]
}
我得到了这样的答复(如您所见,字段是UpperCamelCase):
{
"took": 86,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"skipped": 0,
"failed": 0
},
"hits": {
"total": 1,
"max_score": 1,
"hits": [
{
"_index": "search_tax_map_key",
"_type": "taxMapKey",
"_id": "fbWo3GgB23V4WRXcMn-8",
"_score": 1,
"_source": {
"TransferList": [
{
"Grantor": {
"Price": 220000,
"InstrumentType": "DEED "
}
},
{
"Grantor": {
"Price": 170000,
"InstrumentType": "DEED "
}
},
{
"Grantor": {
"Price": 0,
"InstrumentType": "TRANSD "
}
},
{
"Grantor": {
"Price": 44000,
"InstrumentType": "DEED "
}
},
{
"Grantor": {
"Price": 0,
"InstrumentType": "DEED "
}
}
]
}
}
]
}
}
但是在元数据信息中,我有这样的结构:
curl -X GET \
http://localhost:9200/search_tax_map_key \
-H 'Content-Type: application/json' \
{
"search_tax_map_key": {
"aliases": {},
"mappings": {
"taxMapKey": {
"properties": {
"TransferList": {
"properties": {
"Grantor": {
"properties": {
"DocumentNumber": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"InstrumentType": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"Price": {
"type": "long"
}
}
}
}
},
"transferList": {
"type": "nested",
"include_in_parent": true,
"properties": {
"grantor": {
"type": "nested",
"properties": {
"grantees": {
"type": "nested"
}
}
}
}
}
}
}
},
"settings": {
"index": {
"number_of_shards": "5",
"provided_name": "search_tax_map_key",
"creation_date": "1549963193142",
"analysis": {
"analyzer": {
"case_insensitive": {
"filter": [
"lowercase"
],
"tokenizer": "keyword"
}
}
},
"number_of_replicas": "1",
"uuid": "ZM9jbP_pQAyOAELPsWL2Eg",
"version": {
"created": "6050499"
}
}
}
}
}
如您所见,我有两个对象,例如transferList(命名未转换为大驼峰案例)和另一个TransferList(已转换为大驼峰案例)
由于类似错误,我无法使用大写驼峰命名字段进行请求
查询示例:
{
"_source": false,
"query": {
"nested": {
"path": "TransferList.Grantor",
"inner_hits": {
"_source": ["TransferList.Grantor.Price", "TransferList.Grantor.InstrumentType"]
},
"query" : {
"bool" : {
"should": [
{
"term": {
"TransferList.Grantor.InstrumentType": "deed"
}
},
{
"term": {
"TransferList.Grantor.InstrumentType": "dl"
}
},
{
"term": {
"TransferList.Grantor.InstrumentType": "commd"
}
}
]
}
}
}
},
"aggs" : {
"transferList" : {
"nested": {
"path": "TransferList.Grantor"
},
"aggs": {
"transferListInner": {
"filter": {
"bool" : {
"should": [
{
"term": {
"TransferList.Grantor.InstrumentType": "deed"
}
},
{
"term": {
"TransferList.Grantor.InstrumentType": "dl"
}
},
{
"term": {
"TransferList.Grantor.InstrumentType": "commd"
}
}
]
}
},
"aggs" : {
"max_price": {
"max": {
"field": "TransferList.Grantor.Price"
}
},
"min_price": {
"min": {
"field": "TransferList.Grantor.Price"
}
},
"avg_price": {
"avg": {
"field": "TransferList.Grantor.Price"
}
},
"mode" : {
"terms" : {
"field" : "TransferList.Grantor.Price",
"size": 1
}
}
}
}
}
}
}
}
错误:
{
"error": {
"root_cause": [
{
"type": "query_shard_exception",
"reason": "failed to create query: {\n \"nested\" : {\n \"query\" : {\n \"bool\" : {\n \"should\" : [\n {\n \"term\" : {\n \"TransferList.Grantor.InstrumentType\" : {\n \"value\" : \"deed\",\n \"boost\" : 1.0\n }\n }\n },\n {\n \"term\" : {\n \"TransferList.Grantor.InstrumentType\" : {\n \"value\" : \"dl\",\n \"boost\" : 1.0\n }\n }\n },\n {\n \"term\" : {\n \"TransferList.Grantor.InstrumentType\" : {\n \"value\" : \"commd\",\n \"boost\" : 1.0\n }\n }\n }\n ],\n \"adjust_pure_negative\" : true,\n \"boost\" : 1.0\n }\n },\n \"path\" : \"TransferList.Grantor\",\n \"ignore_unmapped\" : false,\n \"score_mode\" : \"avg\",\n \"boost\" : 1.0,\n \"inner_hits\" : {\n \"ignore_unmapped\" : false,\n \"from\" : 0,\n \"size\" : 3,\n \"version\" : false,\n \"explain\" : false,\n \"track_scores\" : false,\n \"_source\" : {\n \"includes\" : [\n \"TransferList.Grantor.Price\",\n \"TransferList.Grantor.InstrumentType\"\n ],\n \"excludes\" : [ ]\n }\n }\n }\n}",
"index_uuid": "ZM9jbP_pQAyOAELPsWL2Eg",
"index": "search_tax_map_key"
}
],
"type": "search_phase_execution_exception",
"reason": "all shards failed",
"phase": "query",
"grouped": true,
"failed_shards": [
{
"shard": 0,
"index": "search_tax_map_key",
"node": "35Jvwv7vS3qrB0ltlIt3Yg",
"reason": {
"type": "query_shard_exception",
"reason": "failed to create query: {\n \"nested\" : {\n \"query\" : {\n \"bool\" : {\n \"should\" : [\n {\n \"term\" : {\n \"TransferList.Grantor.InstrumentType\" : {\n \"value\" : \"deed\",\n \"boost\" : 1.0\n }\n }\n },\n {\n \"term\" : {\n \"TransferList.Grantor.InstrumentType\" : {\n \"value\" : \"dl\",\n \"boost\" : 1.0\n }\n }\n },\n {\n \"term\" : {\n \"TransferList.Grantor.InstrumentType\" : {\n \"value\" : \"commd\",\n \"boost\" : 1.0\n }\n }\n }\n ],\n \"adjust_pure_negative\" : true,\n \"boost\" : 1.0\n }\n },\n \"path\" : \"TransferList.Grantor\",\n \"ignore_unmapped\" : false,\n \"score_mode\" : \"avg\",\n \"boost\" : 1.0,\n \"inner_hits\" : {\n \"ignore_unmapped\" : false,\n \"from\" : 0,\n \"size\" : 3,\n \"version\" : false,\n \"explain\" : false,\n \"track_scores\" : false,\n \"_source\" : {\n \"includes\" : [\n \"TransferList.Grantor.Price\",\n \"TransferList.Grantor.InstrumentType\"\n ],\n \"excludes\" : [ ]\n }\n }\n }\n}",
"index_uuid": "ZM9jbP_pQAyOAELPsWL2Eg",
"index": "search_tax_map_key",
"caused_by": {
"type": "illegal_state_exception",
"reason": "[nested] nested object under path [TransferList.Grantor] is not of nested type"
}
}
}
]
},
"status": 400
}
如何将@JsonNaming(PropertyNamingStrategy.UpperCamelCaseStrategy.class)用于嵌套字段?