Skip to content
Franklin Wise edited this page Jun 20, 2015 · 1 revision

https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-query-string-query.html#query-string-syntax

Search Patterns:

  • field:"what i'm looking for in that field"
  • ((quick AND fox) OR (brown AND fox) OR fox) AND NOT news
  • status:(active OR pending) title:(full text search)^2
  • count:[1 TO 5]
  • count:[10 TO *]
  • date:{* TO 2012-01-01}
  • age:>=10
  • "fox quick"~5
  • quikc~ brwn~ foks~
  • name:/joh?n(ath[oa]n)/

Boosting

Boosting

Use the boost operator ^ to make one term more relevant than another. For instance, if we want to find all documents about foxes, but we are especially interested in quick foxes:

quick^2 fox The default boost value is 1, but can be any positive floating point number. Boosts between 0 and 1 reduce relevance.

Boosts can also be applied to phrases or to groups:

"john smith"^2 (foo bar)^4

Reserved characters

If you need to use any of the characters which function as operators in your query itself (and not as operators), then you should escape them with a leading backslash. For instance, to search for (1+1)=2, you would need to write your query as (1+1)=2.

The reserved characters are: + - = && || > < ! ( ) { } [ ] ^ " ~ * ? : \ /

Failing to escape these special characters correctly could lead to a syntax error which prevents your query from running.

Watch this space

A space may also be a reserved character. For instance, if you have a synonym list which converts "wi fi" to "wifi", a query_string search for "wi fi" would fail. The query string parser would interpret your query as a search for "wi OR fi", while the token stored in your index is actually "wifi". Escaping the space will protect it from being touched by the query string parser: "wi\ fi".

Clone this wiki locally