elasticsearch spring-data-elastic搜索:如何与CriteriaQuery合并and & or

4urapxun  于 2023-08-03  发布在  ElasticSearch
关注(0)|答案(1)|浏览(127)

我有一个文件与4个领域,为简单起见,A,B,C和D.现在我尝试构建一个CriteriaQuery
((a = 1 AND b = 2 ) OR (a = 3 AND b = 43)) AND D = '4234234'通过创建使用的基本流程
new Criteria("a").is(1).and("b").is(2).and("d").is("4234234")
工作正常。
但我在手术室方面很难让它正常工作。
我以为

new Criteria("d").is("4234234").and(new Criteria("a").is(1).and("b").is(2)).or(new Criteria("a").is(1).and("b").is(2))

字符串
但这会导致分片错误。
有谁能给我指个路吗?

eivgtgni

eivgtgni1#

您可以在Spring Data Elasticsearch的测试代码中找到示例,例如在https://github.com/spring-projects/spring-data-elasticsearch/blob/main/src/test/java/org/springframework/data/elasticsearch/client/elc/CriteriaQueryProcessorUnitTests.java#L167-L309
从创建((John或Jack)和米勒)或((Emma或Lucy)和Smith)的测试之一:

Criteria criteria = Criteria.or()
                .subCriteria(new Criteria("lastName").is("Miller")
                        .subCriteria(new Criteria().or("firstName").is("John").or("firstName").is("Jack")))
                .subCriteria(new Criteria("lastName").is("Smith")
                        .subCriteria(new Criteria().or("firstName").is("Emma").or("firstName").is("Lucy")));

字符串

相关问题