Difference between revisions of "ElasticSearch Query DSL"
Line 5: | Line 5: | ||
== Queries == | == Queries == | ||
− | === match === | + | === match, multi_match === |
− | + | The ''match'' queries accept, analyze, and construct query out of text/numeric/date. The match family of queries does not go through a "query parsing" process. It does not support field name prefixes, wildcard characters, or other "advance" features. | |
+ | |||
+ | Here, ''message'' is name of the '''field to match in''' (can be also ''_all''): | ||
+ | <pre>{ | ||
+ | "match" : { | ||
+ | "message" : "this is a test" | ||
+ | } | ||
+ | }</pre> | ||
+ | |||
+ | By default, terms are OR'ed; to '''AND''' them: | ||
+ | |||
+ | <pre>{ | ||
+ | "match" : { | ||
+ | "message" : { | ||
+ | "query" : "this is a test", | ||
+ | "operator" : "and" | ||
+ | } | ||
+ | } | ||
+ | }</pre> | ||
+ | |||
+ | To '''match a phrase''': | ||
+ | <pre>{ | ||
+ | "match_phrase" : { | ||
+ | "message" : "this is a test" | ||
+ | } | ||
+ | }</pre> | ||
+ | |||
+ | or using the '''last word as prefix''' (the "as you type" search): | ||
+ | <pre>{ | ||
+ | "match_phrase_prefix" : { | ||
+ | "message" : "this is a test" | ||
+ | } | ||
+ | }</pre> | ||
+ | |||
+ | To match in '''multiple fields''', with optional boosting, use: | ||
+ | <pre>{ | ||
+ | "multi_match" : { | ||
+ | "query" : "this is a test", | ||
+ | "fields" : [ "subject^2", "message" ] | ||
+ | } | ||
+ | }</pre> | ||
+ | where matches in ''subject'' are "twice as important" as matched in ''message''. | ||
=== bool === | === bool === |
Revision as of 12:10, 23 January 2013
ES's Query DSL is a language for specifying queries in JSON.
This is by far not an exhaustive documentation, it's just stuff I use the most; see official documentation for more. Especially the boosting and scoring functionality is not documented here to proper extent.
Contents
Queries
match, multi_match
The match queries accept, analyze, and construct query out of text/numeric/date. The match family of queries does not go through a "query parsing" process. It does not support field name prefixes, wildcard characters, or other "advance" features.
Here, message is name of the field to match in (can be also _all):
{ "match" : { "message" : "this is a test" } }
By default, terms are OR'ed; to AND them:
{ "match" : { "message" : { "query" : "this is a test", "operator" : "and" } } }
To match a phrase:
{ "match_phrase" : { "message" : "this is a test" } }
or using the last word as prefix (the "as you type" search):
{ "match_phrase_prefix" : { "message" : "this is a test" } }
To match in multiple fields, with optional boosting, use:
{ "multi_match" : { "query" : "this is a test", "fields" : [ "subject^2", "message" ] } }
where matches in subject are "twice as important" as matched in message.