File tree 5 files changed +25
-14
lines changed
main/java/org/elasticsearch/index/mapper
test/java/org/elasticsearch
5 files changed +25
-14
lines changed Original file line number Diff line number Diff line change @@ -152,16 +152,15 @@ public BytesRef indexedValueForSearch(Object value) {
152
152
} else {
153
153
sValue = value .toString ();
154
154
}
155
- if (sValue . length () == 0 ) {
156
- return Values . FALSE ;
157
- }
158
- if ( sValue . length () == 1 && sValue . charAt ( 0 ) == 'F' ) {
159
- return Values .FALSE ;
160
- }
161
- if ( Booleans . parseBoolean ( sValue , false )) {
162
- return Values . TRUE ;
155
+ switch (sValue ) {
156
+ case "true" :
157
+ return Values . TRUE ;
158
+ case "false" :
159
+ return Values .FALSE ;
160
+ default :
161
+ throw new IllegalArgumentException ( "Can't parse boolean value [" +
162
+ sValue + "], expected [true] or [false]" ) ;
163
163
}
164
- return Values .FALSE ;
165
164
}
166
165
167
166
@ Override
Original file line number Diff line number Diff line change @@ -106,7 +106,7 @@ public void testExternalValues() throws Exception {
106
106
SearchResponse response ;
107
107
108
108
response = client ().prepareSearch ("test-idx" )
109
- .setPostFilter (QueryBuilders .termQuery ("field.bool" , "T " ))
109
+ .setPostFilter (QueryBuilders .termQuery ("field.bool" , "true " ))
110
110
.execute ().actionGet ();
111
111
112
112
assertThat (response .getHits ().totalHits (), equalTo ((long ) 1 ));
Original file line number Diff line number Diff line change @@ -247,6 +247,14 @@ public void testPhraseQueryOnFieldWithNoPositions() throws Exception {
247
247
assertHitCount (resp , 1L );
248
248
}
249
249
250
+ public void testBooleanStrictQuery () throws Exception {
251
+ Exception e = expectThrows (Exception .class , () ->
252
+ client ().prepareSearch ("test" ).setQuery (
253
+ queryStringQuery ("foo" ).field ("f_bool" )).get ());
254
+ assertThat (ExceptionsHelper .detailedMessage (e ),
255
+ containsString ("Can't parse boolean value [foo], expected [true] or [false]" ));
256
+ }
257
+
250
258
private void assertHits (SearchHits hits , String ... ids ) {
251
259
assertThat (hits .totalHits (), equalTo ((long ) ids .length ));
252
260
Set <String > hitIds = new HashSet <>();
Original file line number Diff line number Diff line change @@ -32,21 +32,21 @@ PUT my_index
32
32
33
33
POST my_index/my_type/1
34
34
{
35
- "is_published": true <1>
35
+ "is_published": 1 <1>
36
36
}
37
37
38
38
GET my_index/_search
39
39
{
40
40
"query": {
41
41
"term": {
42
- "is_published": 1 <2>
42
+ "is_published": true <2>
43
43
}
44
44
}
45
45
}
46
46
--------------------------------------------------
47
47
// CONSOLE
48
- <1> Indexing a document with a JSON `true`.
49
- <2> Querying for the document with `1`, which is interpreted as `true`.
48
+ <1> Indexing a document with `1`, which is interpreted as `true`.
49
+ <1> Searching for documents with a JSON `true`.
50
50
51
51
Aggregations like the <<search-aggregations-bucket-terms-aggregation,`terms`
52
52
aggregation>> use `1` and `0` for the `key`, and the strings `"true"` and
Original file line number Diff line number Diff line change 5
5
6
6
* The `collect_payloads` parameter of the `span_near` query has been removed. Payloads will be
7
7
loaded when needed.
8
+
9
+ * Queries on boolean fields now strictly parse boolean-like values. This means
10
+ only the strings `"true"` and `"false"` will be parsed into their boolean
11
+ counterparts. Other strings will cause an error to be thrown.
You can’t perform that action at this time.
0 commit comments