simple-query-string-query.asciidoc 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. [[query-dsl-simple-query-string-query]]
  2. === Simple Query String Query
  3. A query that uses the SimpleQueryParser to parse its context. Unlike the
  4. regular `query_string` query, the `simple_query_string` query will never
  5. throw an exception, and discards invalid parts of the query. Here is
  6. an example:
  7. [source,js]
  8. --------------------------------------------------
  9. {
  10. "simple_query_string" : {
  11. "query": "\"fried eggs\" +(eggplant | potato) -frittata",
  12. "analyzer": "snowball",
  13. "fields": ["body^5","_all"],
  14. "default_operator": "and"
  15. }
  16. }
  17. --------------------------------------------------
  18. The `simple_query_string` top level parameters include:
  19. [cols="<,<",options="header",]
  20. |=======================================================================
  21. |Parameter |Description
  22. |`query` |The actual query to be parsed. See below for syntax.
  23. |`fields` |The fields to perform the parsed query against. Defaults to the
  24. `index.query.default_field` index settings, which in turn defaults to `_all`.
  25. |`default_operator` |The default operator used if no explicit operator
  26. is specified. For example, with a default operator of `OR`, the query
  27. `capital of Hungary` is translated to `capital OR of OR Hungary`, and
  28. with default operator of `AND`, the same query is translated to
  29. `capital AND of AND Hungary`. The default value is `OR`.
  30. |`analyzer` |The analyzer used to analyze each term of the query when
  31. creating composite queries.
  32. |`flags` |Flags specifying which features of the `simple_query_string` to
  33. enable. Defaults to `ALL`.
  34. |`lowercase_expanded_terms` | Whether terms of prefix and fuzzy queries are to
  35. be automatically lower-cased or not (since they are not analyzed). Defaults to
  36. true.
  37. |`locale` | Locale that should be used for string conversions.
  38. Defaults to `ROOT`.
  39. |`lenient` | If set to `true` will cause format based failures
  40. (like providing text to a numeric field) to be ignored.
  41. |=======================================================================
  42. [float]
  43. ==== Simple Query String Syntax
  44. The `simple_query_string` supports the following special characters:
  45. * `+` signifies AND operation
  46. * `|` signifies OR operation
  47. * `-` negates a single token
  48. * `"` wraps a number of tokens to signify a phrase for searching
  49. * `*` at the end of a term signifies a prefix query
  50. * `(` and `)` signify precedence
  51. * `~N` after a word signifies edit distance (fuzziness)
  52. * `~N` after a phrase signifies slop amount
  53. In order to search for any of these special characters, they will need to
  54. be escaped with `\`.
  55. [float]
  56. ==== Default Field
  57. When not explicitly specifying the field to search on in the query
  58. string syntax, the `index.query.default_field` will be used to derive
  59. which field to search on. It defaults to `_all` field.
  60. So, if `_all` field is disabled, it might make sense to change it to set
  61. a different default field.
  62. [float]
  63. ==== Multi Field
  64. The fields parameter can also include pattern based field names,
  65. allowing to automatically expand to the relevant fields (dynamically
  66. introduced fields included). For example:
  67. [source,js]
  68. --------------------------------------------------
  69. {
  70. "simple_query_string" : {
  71. "fields" : ["content", "name.*^5"],
  72. "query" : "foo bar baz"
  73. }
  74. }
  75. --------------------------------------------------
  76. [float]
  77. ==== Flags
  78. `simple_query_string` support multiple flags to specify which parsing features
  79. should be enabled. It is specified as a `|`-delimited string with the
  80. `flags` parameter:
  81. [source,js]
  82. --------------------------------------------------
  83. {
  84. "simple_query_string" : {
  85. "query" : "foo | bar & baz*",
  86. "flags" : "OR|AND|PREFIX"
  87. }
  88. }
  89. --------------------------------------------------
  90. The available flags are: `ALL`, `NONE`, `AND`, `OR`, `NOT`, `PREFIX`, `PHRASE`,
  91. `PRECEDENCE`, `ESCAPE`, `WHITESPACE`, `FUZZY`, `NEAR`, and `SLOP`.