Spring Data API(Containing或Startwith)无法与具有通配符的SPACE一起使用 [英] Spring Data api (Containing or startwith) not working with SPACE which has wildcard
问题描述
我正在对Spring Data使用Elastic Search.
I am using Elastic Search with Spring Data .
我在存储库中有一个简单的方法:
I have a simple method in repository:
findByUserNameContaining("a b");
由于SPACE,此方法未提供预期结果.
This method not giving expecting result because of SPACE.
获取错误:
""无法构造查询'"a b" '.改为使用表达式或多个子句.EXCEPTION ="org.springframework.dao.InvalidDataAccessApiUsageException:无法构造查询'" a b"'.请使用表达式或多个子句.
"Cannot constructQuery '"a b"'. Use expression or multiple clauses instead." EXCEPTION="org.springframework.dao.InvalidDataAccessApiUsageException: Cannot constructQuery '"a b"'. Use expression or multiple clauses instead.
用于由于空间原因而停止创建多个令牌.我有映射:
For stopping creation of multiple tokens because of Space. I have mapping:
"userName": {
"type": "string",
"index": "not_analyzed"
},
对于在映射中"index":"not_analyzed"
之后出现此问题,我感到非常惊讶.
I am totally surprised that I am getting this issue after "index": "not_analyzed"
in mapping .
请帮助我.预先感谢!
推荐答案
实际上,Spring数据api(包含或startWith)不适用于String中的空格.我已经用Elastic core api实现了相同的功能.
Actually Spring data apis (containing or startWith) does not work with space in String . I have implemented same with Elastic core api.
NativeSearchQueryBuilder aNativeSearchQueryBuilder = new NativeSearchQueryBuilder();
aNativeSearchQueryBuilder.withIndices(indexName).withTypes(type);
final BoolQueryBuilder aQuery = new BoolQueryBuilder();
aQuery.must(QueryBuilders.queryStringQuery("a b").defaultField("UserName"));
NativeSearchQuery nativeSearchQuery = aNativeSearchQueryBuilder.withQuery(aQuery).build();
List<Object> aDatas = elasticsearchTemplate.queryForList(nativeSearchQuery, Object.class);
这篇关于Spring Data API(Containing或Startwith)无法与具有通配符的SPACE一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!