我有一个关于Spring的项目。型号:
@Document(indexName = "house", createIndex = false)
public class House {
@Id
private String id;
private String aoGuid;
private String buildNum;
private String houseGuid;
private String houseId;
private String houseNum;
private String postalCode;
private String regionCode;
}储存库:
@Query("{\n" +
" \"bool\": {\n" +
" \"must\": [\n" +
" {\n" +
" \"bool\": {\n" +
" \"must\": [\n" +
" {\n" +
" \"terms\": {\n" +
" \"aoGuid\": \"[?0]\"\n" +
" }\n" +
" }\n" +
" ]\n" +
" }\n" +
" }\n" +
" ]\n" +
" }\n" +
"}")
List<House> findByAoGuidIn(Collection<String> aoGuid);我的弹性索引:
{
"house": {
"aliases": {},
"mappings": {
"properties": {
"_class": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"aoGuid": {
"type": "keyword"
},
"buildNum": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"houseGuid": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"houseId": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"houseNum": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"postalCode": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"regionCode": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
}
}
},
"settings": {
"index": {
"search": {
"slowlog": {
"threshold": {
"query": {
"info": "1ms"
}
}
}
},
"number_of_shards": "1",
"provided_name": "house",
"creation_date": "1582210642568",
"number_of_replicas": "1",
"uuid": "c43T1LthTH6LhTphjZ-Ulw",
"version": {
"created": "7040099"
}
}
}
}
}当我调用findByAoGuidIn方法时,会得到一个错误:
org.elasticsearch.ElasticsearchStatusException:
弹性搜索异常[type=parsing_exception,org.elasticsearch.rest.BytesRestResponse.errorFromXContent(BytesRestResponse.java:177) ~elasticsearch-7.4.0.jar:7.4.0 at org.elasticsearch.client.RestHighLevelClient.parseEntity(RestHighLevelClient.java:1727) ~elasticsearch-rest-high-level-client-7.4.0.jar:7.4.0 at org.elasticsearch.client.RestHighLevelClient.parseResponseException(RestHighLevelClient.java:1704) ~elasticsearch-rest-高级别-client-7。4.0.jar:7.4.0在org.elasticsearch.client.RestHighLevelClient.internalPerformRequest(RestHighLevelClient.java:1467) ~elasticsearch-rest-high-level-client-7.4.0.jar:7.4.0 at org.elasticsearch.client.RestHighLevelClient.performRequest(RestHighLevelClient.java:1424) ~elasticsearch-rest-high-level-client-7.4.0.jar:7.4.0 at org.elasticsearch.client.RestHighLevelClient.performRequestAndParseEntity(RestHighLevelClient.java:1394) ~elasticsearch-rest-高级-客户-7.4.0.jar:7.4.0
我从以下链接的文档中获得了一个查询:https://docs.spring.io/spring-data/elasticsearch/docs/4.0.x/reference/html/#elasticsearch.query-methods
我怎样才能纠正错误?
发布于 2020-02-21 07:58:17
“谢谢,”瓦尔,你引导我走上了正确的道路。问题是我是如何形成收藏的。我的问题中没有提到这一点。我贴出了修正后的代码:
List<String> aoGuidList = new ArrayList<>();
it.getParts().forEach(itt -> {
aoGuidList.add("\"" + itt.getAoGuid() + "\"");
});
queryHouseService.search(aoGuidList);现在我的存储库:
@Query("{\n" +
" \"bool\": {\n" +
" \"must\": [\n" +
" {\n" +
" \"bool\": {\n" +
" \"must\": [\n" +
" {\n" +
" \"terms\": {\n" +
" \"aoGuid\": ?0\n" +
" }\n" +
" }\n" +
" ]\n" +
" }\n" +
" }\n" +
" ]\n" +
" }\n" +
"}")
List<House> findByAoGuidIn(Collection<String> aoGuid);实际上,我必须确保请求中的集合符合"val1“、"val2”的模式。在我错误的版本中,我得到了一个表单的集合:val1、val2或"val1,val2“。
https://stackoverflow.com/questions/60323342
复制相似问题