@@ -28,14 +28,14 @@ GET /_search
28
28
"query": {
29
29
"query_string" : {
30
30
"default_field" : "content",
31
- "query" : "(new york city) OR (big apple)"
31
+ "query" : "(new york city) OR (big apple)" <1>
32
32
}
33
33
}
34
34
}
35
35
--------------------------------------------------
36
36
// CONSOLE
37
37
38
- ... will be split into `new york city` and `big apple` and each part is then
38
+ <1> will be split into `new york city` and `big apple` and each part is then
39
39
analyzed independently by the analyzer configured for the field.
40
40
41
41
WARNING: Whitespaces are not considered operators, this means that `new york city`
@@ -48,7 +48,6 @@ When multiple fields are provided it is also possible to modify how the differen
48
48
field queries are combined inside each textual part using the `type` parameter.
49
49
The possible modes are described <<multi-match-types, here>> and the default is `best_fields`.
50
50
51
-
52
51
The `query_string` top level parameters include:
53
52
54
53
[cols="<,<",options="header",]
@@ -107,8 +106,8 @@ not analyzed. By setting this value to `true`, a best effort will be
107
106
made to analyze those as well.
108
107
109
108
|`max_determinized_states` |Limit on how many automaton states regexp
110
- queries are allowed to create. This protects against too-difficult
111
- (e.g. exponentially hard) regexps. Defaults to 10000.
109
+ queries are allowed to create. This protects against too-difficult
110
+ (e.g. exponentially hard) regexps. Defaults to 10000.
112
111
113
112
|`minimum_should_match` |A value controlling how many "should" clauses
114
113
in the resulting boolean query should match. It can be an absolute value
@@ -154,7 +153,7 @@ fields in the mapping could be expensive.
154
153
==== Multi Field
155
154
156
155
The `query_string` query can also run against multiple fields. Fields can be
157
- provided via the `" fields" ` parameter (example below).
156
+ provided via the `fields` parameter (example below).
158
157
159
158
The idea of running the `query_string` query against multiple fields is to
160
159
expand each query term to an OR clause like this:
@@ -194,7 +193,7 @@ GET /_search
194
193
// CONSOLE
195
194
196
195
Since several queries are generated from the individual search terms,
197
- combining them is automatically done using a `dis_max` query with a tie_breaker.
196
+ combining them is automatically done using a `dis_max` query with a ` tie_breaker` .
198
197
For example (the `name` is boosted by 5 using `^5` notation):
199
198
200
199
[source,js]
@@ -289,7 +288,7 @@ GET /_search
289
288
290
289
The `query_string` query supports multi-terms synonym expansion with the <<analysis-synonym-graph-tokenfilter,
291
290
synonym_graph>> token filter. When this filter is used, the parser creates a phrase query for each multi-terms synonyms.
292
- For example, the following synonym: `" ny, new york" would produce:`
291
+ For example, the following synonym: `ny, new york` would produce:
293
292
294
293
`(ny OR ("new york"))`
295
294
@@ -317,4 +316,121 @@ The example above creates a boolean query:
317
316
that matches documents with the term `ny` or the conjunction `new AND york`.
318
317
By default the parameter `auto_generate_synonyms_phrase_query` is set to `true`.
319
318
319
+ [float]
320
+ ==== Minimum should match
321
+
322
+ The `query_string` splits the query around each operator to create a boolean
323
+ query for the entire input. You can use `minimum_should_match` to control how
324
+ many "should" clauses in the resulting query should match.
325
+
326
+ [source,js]
327
+ --------------------------------------------------
328
+ GET /_search
329
+ {
330
+ "query": {
331
+ "query_string": {
332
+ "fields": [
333
+ "title"
334
+ ],
335
+ "query": "this that thus",
336
+ "minimum_should_match": 2
337
+ }
338
+ }
339
+ }
340
+ --------------------------------------------------
341
+ // CONSOLE
342
+
343
+ The example above creates a boolean query:
344
+
345
+ `(title:this title:that title:thus)~2`
346
+
347
+ that matches documents with at least two of the terms `this`, `that` or `thus`
348
+ in the single field `title`.
349
+
350
+ [float]
351
+ ===== Multi Field
352
+
353
+ [source,js]
354
+ --------------------------------------------------
355
+ GET /_search
356
+ {
357
+ "query": {
358
+ "query_string": {
359
+ "fields": [
360
+ "title",
361
+ "content"
362
+ ],
363
+ "query": "this that thus",
364
+ "minimum_should_match": 2
365
+ }
366
+ }
367
+ }
368
+ --------------------------------------------------
369
+ // CONSOLE
370
+
371
+ The example above creates a boolean query:
372
+
373
+ `((content:this content:that content:thus) | (title:this title:that title:thus))`
374
+
375
+ that matches documents with the disjunction max over the fields `title` and
376
+ `content`. Here the `minimum_should_match` parameter can't be applied.
377
+
378
+ [source,js]
379
+ --------------------------------------------------
380
+ GET /_search
381
+ {
382
+ "query": {
383
+ "query_string": {
384
+ "fields": [
385
+ "title",
386
+ "content"
387
+ ],
388
+ "query": "this OR that OR thus",
389
+ "minimum_should_match": 2
390
+ }
391
+ }
392
+ }
393
+ --------------------------------------------------
394
+ // CONSOLE
395
+
396
+ Adding explicit operators forces each term to be considered as a separate clause.
397
+
398
+ The example above creates a boolean query:
399
+
400
+ `((content:this | title:this) (content:that | title:that) (content:thus | title:thus))~2`
401
+
402
+ that matches documents with at least two of the three "should" clauses, each of
403
+ them made of the disjunction max over the fields for each term.
404
+
405
+ [float]
406
+ ===== Cross Field
407
+
408
+ [source,js]
409
+ --------------------------------------------------
410
+ GET /_search
411
+ {
412
+ "query": {
413
+ "query_string": {
414
+ "fields": [
415
+ "title",
416
+ "content"
417
+ ],
418
+ "query": "this OR that OR thus",
419
+ "type": "cross_fields",
420
+ "minimum_should_match": 2
421
+ }
422
+ }
423
+ }
424
+ --------------------------------------------------
425
+ // CONSOLE
426
+
427
+ The `cross_fields` value in the `type` field indicates that fields that have the
428
+ same analyzer should be grouped together when the input is analyzed.
429
+
430
+ The example above creates a boolean query:
431
+
432
+ `(blended(terms:[field2:this, field1:this]) blended(terms:[field2:that, field1:that]) blended(terms:[field2:thus, field1:thus]))~2`
433
+
434
+ that matches documents with at least two of the three per-term blended queries.
435
+
320
436
include::query-string-syntax.asciidoc[]
0 commit comments