20
20
package org .elasticsearch .index .query ;
21
21
22
22
import org .apache .lucene .search .Query ;
23
+ import org .elasticsearch .action .support .ToXContentToBytes ;
23
24
import org .elasticsearch .common .io .stream .StreamInput ;
24
25
import org .elasticsearch .common .io .stream .StreamOutput ;
25
26
import org .elasticsearch .common .xcontent .XContentBuilder ;
27
+ import org .elasticsearch .common .xcontent .XContentType ;
26
28
27
29
import java .io .IOException ;
28
30
35
37
* intended to be used internally as a stand-in for nested queries that are left empty and should
36
38
* be ignored upstream.
37
39
*/
38
- public class EmptyQueryBuilder extends AbstractQueryBuilder <EmptyQueryBuilder > {
40
+ public class EmptyQueryBuilder extends ToXContentToBytes implements QueryBuilder <EmptyQueryBuilder > {
39
41
40
42
public static final String NAME = "empty_query" ;
41
43
42
44
/** the one and only empty query builder */
43
45
public static final EmptyQueryBuilder PROTOTYPE = new EmptyQueryBuilder ();
44
46
47
+ // prevent instances other than prototype
45
48
private EmptyQueryBuilder () {
46
- // prevent other constructors
49
+ super ( XContentType . JSON );
47
50
}
48
51
49
52
@ Override
@@ -52,16 +55,15 @@ public String getName() {
52
55
}
53
56
54
57
@ Override
55
- protected void doXContent (XContentBuilder builder , Params params ) throws IOException {
56
- // empty
58
+ public XContentBuilder toXContent (XContentBuilder builder , Params params ) throws IOException {
59
+ builder .startObject ();
60
+ builder .endObject ();
61
+ return builder ;
57
62
}
58
63
59
- /**
60
- * @returns <tt>null</tt> to signal to caller that this query should be ignored
61
- * in the context of the DSL.
62
- */
63
64
@ Override
64
- public Query doToQuery (QueryParseContext parseContext ) throws QueryParsingException , IOException {
65
+ public Query toQuery (QueryParseContext parseContext ) throws IOException {
66
+ // empty
65
67
return null ;
66
68
}
67
69
@@ -72,12 +74,11 @@ public QueryValidationException validate() {
72
74
}
73
75
74
76
@ Override
75
- public EmptyQueryBuilder doReadFrom (StreamInput in ) throws IOException {
76
- return EmptyQueryBuilder .PROTOTYPE ;
77
+ public void writeTo (StreamOutput out ) throws IOException {
77
78
}
78
79
79
80
@ Override
80
- public void doWriteTo ( StreamOutput out ) throws IOException {
81
- // nothing to serialize
81
+ public EmptyQueryBuilder readFrom ( StreamInput in ) throws IOException {
82
+ return EmptyQueryBuilder . PROTOTYPE ;
82
83
}
83
84
}
0 commit comments