Commit 9e38a85b authored by Maxym Borodenko's avatar Maxym Borodenko

Merge branch '491-es-text-query-issue' into 'master'

Resolve "ES: Text query issue"

Closes #491

See merge request genesys-pgr/genesys-server!508
parents fedc2947 233dc9e5
......@@ -48,23 +48,12 @@ public class ElasticQueryBuilder implements Visitor<Void, Void> {
private final ElasticQueryBuilder self = this;
public QueryBuilder getQuery() {
if (size() == 1) {
if (mustClauses.size() > 0) {
return mustClauses.get(0);
} else if (mustNotClauses.size() > 0) {
return mustNotClauses.get(0);
} else {
throw new RuntimeException("Emm, no");
// return shouldClauses.get(0);
}
} else {
BoolQueryBuilder root = QueryBuilders.boolQuery();
mustClauses.forEach(must -> root.filter(must));
mustNotClauses.forEach(mustNot -> root.mustNot(mustNot));
// shouldClauses.forEach(should -> root.should(should));
// if (shouldClauses.size() > 0) root.minimumNumberShouldMatch(1);
return root;
}
BoolQueryBuilder root = QueryBuilders.boolQuery();
mustClauses.forEach(must -> root.filter(must));
mustNotClauses.forEach(mustNot -> root.mustNot(mustNot));
// shouldClauses.forEach(should -> root.should(should));
// if (shouldClauses.size() > 0) root.minimumNumberShouldMatch(1);
return root;
}
private String customizedPath(String path) {
......
......@@ -72,7 +72,7 @@ public class EsQueryTest {
QueryBuilder esQuery = visitor.getQuery();
LOG.debug("ES query: {}", visitor.getQuery());
JSONArray storages = JsonPath.read(esQuery.toString(), "bool.filter[*].bool.filter[*].terms.storage");
JSONArray storages = JsonPath.read(esQuery.toString(), "bool.filter.bool.filter[*].bool.filter[*].terms.storage");
assertThat(storages.get(0), notNullValue());
assertThat(((List<?>) storages.get(0)), hasSize(1));
assertThat(((List<?>) storages.get(0)), containsInAnyOrder(30));
......@@ -88,7 +88,7 @@ public class EsQueryTest {
QueryBuilder esQuery = visitor.getQuery();
LOG.debug("ES query: {}", visitor.getQuery());
JSONArray storages = JsonPath.read(esQuery.toString(), "bool.filter[*].bool.filter[*].terms.storage");
JSONArray storages = JsonPath.read(esQuery.toString(), "bool.filter.bool.filter[*].bool.filter[*].terms.storage");
assertThat(storages.get(0), notNullValue());
assertThat(((List<?>) storages.get(0)), hasSize(2));
assertThat(((List<?>) storages.get(0)), containsInAnyOrder(20, 10));
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment