Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit bf4e416

Browse files
committed
fix nested类型字段不存在的情况下,用elasticsearch-sql无法查询到 NLPchina#628
1 parent ae34a7b commit bf4e416

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<modelVersion>4.0.0</modelVersion>
44
<groupId>org.nlpcn</groupId>
55
<artifactId>elasticsearch-sql</artifactId>
6-
<version>6.2.2.1</version>
6+
<version>6.2.2.2</version>
77
<packaging>jar</packaging>
88
<description>Query elasticsearch using SQL</description>
99
<name>elasticsearch-sql</name>

src/main/java/org/nlpcn/es4sql/query/maker/QueryMaker.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,13 @@ private void addSubQuery(BoolQueryBuilder boolQuery, Where where, QueryBuilder s
6363
if(where instanceof Condition){
6464
Condition condition = (Condition) where;
6565

66-
if(condition.isNested()){
66+
if (condition.isNested()) {
67+
// bugfix #628
68+
if ("missing".equalsIgnoreCase(String.valueOf(condition.getValue())) && (condition.getOpear() == Condition.OPEAR.IS || condition.getOpear() == Condition.OPEAR.EQ)) {
69+
boolQuery.mustNot(QueryBuilders.nestedQuery(condition.getNestedPath(), QueryBuilders.boolQuery().mustNot(subQuery), ScoreMode.None));
70+
return;
71+
}
72+
6773
subQuery = QueryBuilders.nestedQuery(condition.getNestedPath(), subQuery, ScoreMode.None);
6874
} else if(condition.isChildren()) {
6975
subQuery = JoinQueryBuilders.hasChildQuery(condition.getChildType(), subQuery, ScoreMode.None);

0 commit comments

Comments
 (0)