Elastic Search DSL
Basic Query
Returns documents that contain an indexed value for a field
.
GET /_search
{
"query": {
"exists": {
"field": "user"
}
}
}
The following search returns documents that are missing an indexed value for the user.id
field.
GET /_search
{
"query": {
"bool": {
"must_not": {
"exists": {
"field": "user.id"
}
}
}
}
}
Returns documents that contain terms similar to the search term, as measured by a Levenshtein edit distance.
GET /_search
{
"query": {
"fuzzy": {
"filed_A": {
"value": "ki"
}
}
}
}
Returns documents that contain terms similar to the search term, as measured by a Levenshtein edit distance.
GET /_search
{
"query": {
"fuzzy": {
"filed_A": {
"value": "ki",
"fuzziness": "AUTO",
"max_expansions": 50,
"prefix_length": 0,
"transpositions": true,
"rewrite": "constant_score_blended"
}
}
}
}
rewrite:
- constant_score_boolean
- constant_score_filter
- top_terms_blended_freqs_N
- top_terms_boost_N, top_terms_N
- frequent_terms, score_delegating
Returns documents based on their IDs. This query uses document IDs stored in the _id
field.
GET /_search
{
"query": {
"ids" : {
"values" : ["2NTC5ZIBNLuBWC6V5_0Y"]
}
}
}
The following search returns documents where the filed_A
field contains a term that begins with ki
.
GET /_search
{
"query": {
"prefix": {
"filed_A": {
"value": "ki",
"rewrite": "constant_score_blended",
"case_insensitive": true
}
}
}
}
You can simplify the prefix query syntax by combining the <field>
and value
parameters.
GET /_search
{
"query": {
"prefix" : { "filed_A" : "ki" }
}
}
Returns documents that contain terms within a provided range.
GET /_search
{
"query": {
"range": {
"filed_number": {
"gte": 10,
"lte": 20,
"boost": 2.0
}
}
}
}
GET /_search
{
"query": {
"range": {
"filed_timestamp": {
"time_zone": "+01:00",
"gte": "2020-01-01T00:00:00",
"lte": "now"
}
}
}
}
Returns documents that contain terms matching a regular expression.
GET /_search
{
"query": {
"regexp": {
"filed_A": {
"value": "k.*y",
"flags": "ALL",
"case_insensitive": true,
"max_determinized_states": 10000,
"rewrite": "constant_score_blended"
}
}
}
}
Returns documents that contain an exact term in a provided field.
You can use the term query to find documents based on a precise value such as a price, a product ID, or a username.
GET /_search
{
"query": {
"term": {
"filed_A": {
"value": "kimchy",
"boost": 1.0
}
}
}
}
Returns documents that contain terms matching a wildcard pattern.
A wildcard operator is a placeholder that matches one or more characters. For example, the * wildcard operator matches zero or more characters. You can combine wildcard operators with other characters to create a wildcard pattern.
GET /_search
{
"query": {
"wildcard": {
"filed_A": {
"value": "ki*y",
"boost": 1.0,
"rewrite": "constant_score_blended"
}
}
}
}