use of org.springframework.data.elasticsearch.core.query.Criteria in project spring-data-elasticsearch by spring-projects.
the class CriteriaQueryProcessorUnitTests method shouldProcessTwoCriteriaWithOr.
// DATAES-706
@Test
void shouldProcessTwoCriteriaWithOr() throws JSONException {
String expected = //
"{\n" + //
" \"bool\": {\n" + //
" \"should\": [\n" + //
" {\n" + //
" \"query_string\": {\n" + //
" \"query\": \"value1\",\n" + //
" \"fields\": [\n" + //
" \"field1^1.0\"\n" + //
" ]\n" + //
" }\n" + //
" },\n" + //
" {\n" + //
" \"query_string\": {\n" + //
" \"query\": \"value2\",\n" + //
" \"fields\": [\n" + //
" \"field2^1.0\"\n" + //
" ]\n" + //
" }\n" + //
" }\n" + //
" ]\n" + //
" }\n" + //
"}";
Criteria criteria = new Criteria("field1").is("value1").or("field2").is("value2");
String query = queryProcessor.createQuery(criteria).toString();
assertEquals(expected, query, false);
}
use of org.springframework.data.elasticsearch.core.query.Criteria in project spring-data-elasticsearch by spring-projects.
the class CriteriaQueryProcessorUnitTests method shouldBuildMatchAllQuery.
// DATAES-706
@Test
void shouldBuildMatchAllQuery() throws JSONException {
String expected = //
"{\n" + //
" \"bool\" : {\n" + //
" \"must\" : [\n" + //
" {\n" + //
" \"match\" : {\n" + //
" \"field1\" : {\n" + //
" \"query\" : \"value1 value2\",\n" + //
" \"operator\" : \"AND\"\n" + //
" }\n" + //
" }\n" + //
" }\n" + //
" ]\n" + //
" }\n" + //
"}\n";
Criteria criteria = new Criteria("field1").matchesAll("value1 value2");
String query = queryProcessor.createQuery(criteria).toString();
assertEquals(expected, query, false);
}
use of org.springframework.data.elasticsearch.core.query.Criteria in project spring-data-elasticsearch by spring-projects.
the class CriteriaQueryProcessorUnitTests method shouldProcessMixedCriteriaWithOrAnd.
// DATAES-706
@Test
void shouldProcessMixedCriteriaWithOrAnd() throws JSONException {
String expected = //
"{\n" + //
" \"bool\": {\n" + //
" \"must\": [\n" + //
" {\n" + //
" \"query_string\": {\n" + //
" \"query\": \"value1\",\n" + //
" \"fields\": [\n" + //
" \"field1^1.0\"\n" + //
" ]\n" + //
" }\n" + //
" },\n" + //
" {\n" + //
" \"query_string\": {\n" + //
" \"query\": \"value3\",\n" + //
" \"fields\": [\n" + //
" \"field3^1.0\"\n" + //
" ]\n" + //
" }\n" + //
" }\n" + //
" ],\n" + //
" \"should\": [\n" + //
" {\n" + //
" \"query_string\": {\n" + //
" \"query\": \"value2\",\n" + //
" \"fields\": [\n" + //
" \"field2^1.0\"\n" + //
" ]\n" + //
" }\n" + //
" },\n" + //
" {\n" + //
" \"query_string\": {\n" + //
" \"query\": \"value4\",\n" + //
" \"fields\": [\n" + //
" \"field4^1.0\"\n" + //
" ]\n" + //
" }\n" + //
" }\n" + //
" ]\n" + //
" }\n" + //
"}\n";
Criteria criteria = //
new Criteria("field1").is("value1").or("field2").is(//
"value2").and("field3").is(//
"value3").or("field4").is(//
"value4");
String query = queryProcessor.createQuery(criteria).toString();
assertEquals(expected, query, false);
}
use of org.springframework.data.elasticsearch.core.query.Criteria in project spring-data-elasticsearch by spring-projects.
the class CriteriaQueryProcessorUnitTests method shouldBuildQueryForEmptyProperty.
// #1909
@Test
@DisplayName("should build query for empty property")
void shouldBuildQueryForEmptyProperty() throws JSONException {
String expected = //
"{\n" + //
" \"bool\" : {\n" + //
" \"must\" : [\n" + //
" {\n" + //
" \"bool\" : {\n" + //
" \"must\" : [\n" + //
" {\n" + //
" \"exists\" : {\n" + //
" \"field\" : \"lastName\"" + //
" }\n" + //
" }\n" + //
" ],\n" + //
" \"must_not\" : [\n" + //
" {\n" + //
" \"wildcard\" : {\n" + //
" \"lastName\" : {\n" + //
" \"wildcard\" : \"*\"" + //
" }\n" + //
" }\n" + //
" }\n" + //
" ]\n" + //
" }\n" + //
" }\n" + //
" ]\n" + //
" }\n" + //
"}";
Criteria criteria = new Criteria("lastName").empty();
String query = queryProcessor.createQuery(criteria).toString();
assertEquals(expected, query, false);
}
use of org.springframework.data.elasticsearch.core.query.Criteria in project spring-data-elasticsearch by spring-projects.
the class CriteriaQueryProcessorUnitTests method shouldProcessNestedSubCriteria.
// DATAES-706
@Test
void shouldProcessNestedSubCriteria() throws JSONException {
String expected = //
"{\n" + //
" \"bool\": {\n" + //
" \"should\": [\n" + //
" {\n" + //
" \"bool\": {\n" + //
" \"must\": [\n" + //
" {\n" + //
" \"query_string\": {\n" + //
" \"query\": \"Miller\",\n" + //
" \"fields\": [\n" + //
" \"lastName^1.0\"\n" + //
" ]\n" + //
" }\n" + //
" },\n" + //
" {\n" + //
" \"bool\": {\n" + //
" \"should\": [\n" + //
" {\n" + //
" \"query_string\": {\n" + //
" \"query\": \"Jack\",\n" + //
" \"fields\": [\n" + //
" \"firstName^1.0\"\n" + //
" ]\n" + //
" }\n" + //
" },\n" + //
" {\n" + //
" \"query_string\": {\n" + //
" \"query\": \"John\",\n" + //
" \"fields\": [\n" + //
" \"firstName^1.0\"\n" + //
" ]\n" + //
" }\n" + //
" }\n" + //
" ]\n" + //
" }\n" + //
" }\n" + //
" ]\n" + //
" }\n" + //
" },\n" + //
" {\n" + //
" \"bool\": {\n" + //
" \"must\": [\n" + //
" {\n" + //
" \"query_string\": {\n" + //
" \"query\": \"Smith\",\n" + //
" \"fields\": [\n" + //
" \"lastName^1.0\"\n" + //
" ]\n" + //
" }\n" + //
" },\n" + //
" {\n" + //
" \"bool\": {\n" + //
" \"should\": [\n" + //
" {\n" + //
" \"query_string\": {\n" + //
" \"query\": \"Emma\",\n" + //
" \"fields\": [\n" + //
" \"firstName^1.0\"\n" + //
" ]\n" + //
" }\n" + //
" },\n" + //
" {\n" + //
" \"query_string\": {\n" + //
" \"query\": \"Lucy\",\n" + //
" \"fields\": [\n" + //
" \"firstName^1.0\"\n" + //
" ]\n" + //
" }\n" + //
" }\n" + //
" ]\n" + //
" }\n" + //
" }\n" + //
" ]\n" + //
" }\n" + //
" }\n" + //
" ]\n" + //
" }\n" + //
"}";
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")));
String query = queryProcessor.createQuery(criteria).toString();
assertEquals(expected, query, false);
}
Aggregations