Skip to content

Instantly share code, notes, and snippets.

@stevepop
Last active August 29, 2015 14:08
Show Gist options
  • Save stevepop/b2ca491fbb7ec61a83ae to your computer and use it in GitHub Desktop.
Save stevepop/b2ca491fbb7ec61a83ae to your computer and use it in GitHub Desktop.
Sample Elasticsearch Queries
GET /products/_mapping?pretty=true
GET /products_multi_tagged/_mapping?pretty=true
POST products_multi_tagged/_search?pretty=true
{
"query": {
"bool": {
"should": [
{
"match": {
"department_name_analyzed": {
"type": "phrase",
"slop": 10,
"query": "kitchen tcp"
}
}
},
{
"match": {
"name": "kitchen tcp"
}
},
{
"match": {
"description": "kitchen tcp"
}
}
]
}
},
"facets": {
"department_name": {
"terms": {
"field": "department_name"
}
}
}
}
POST products_multi_tagged/_search?pretty=true
{
"query": {
"filtered": {
"filter": {
"bool": {
"should": [
{
"term": {
"department_name": "Housewares"
}
},
{
"term": {
"department_name": "Kitchen"
}
}
]
}
}
}
},
"facets": {
"department_name": {
"terms": {
"field": "department_name"
}
}
}
}
POST products_multi_tagged/_search?pretty=true
{
"query": {
"match_all": {}
},
"facets": {
"department_name": {
"terms": {
"field": "department_name"
}
}
}
}
POST products/_search?pretty=true
{
"query": {
"match_all": {}
},
"facets": {
"department_id": {
"terms": {
"field": "department_id"
}
},
"department_name": {
"terms": {
"field": "department_name"
}
}
}
}
POST products/_search?pretty=true
{
"query": {
"filtered": {
"query": {
"match": {
"_all": "network routing"
}
},
"filter": {
"term": {
"department_id": 1
}
}
}
}
}
POST products/_search?pretty=true
{
"query": {
"match": {
"_all": "network routing"
}
},
"facets": {
"department_id": {
"terms": {
"field": "department_id"
}
},
"department_name": {
"terms": {
"field": "department_name"
}
},
"price": {
"histogram": {
"field": "price",
"interval": 5000
}
}
}
}
POST products/_search?pretty=true
{
"query": {
"filtered": {
"query": {
"match": {
"_all": "network routing"
}
},
"filter": {
"and": [
{
"range": {
"price": {
"gte": 0,
"lte": 5000
}
}
}
]
}
}
},
"facets": {
"department_id": {
"terms": {
"field": "department_id"
}
},
"department_name": {
"terms": {
"field": "department_name"
}
},
"price": {
"histogram": {
"field": "price",
"interval": 5000
}
}
}
}
POST products/_search?pretty=true
{
"query": {
"filtered": {
"query": {
"match": {
"_all": "network routing"
}
},
"filter": {
"and": [
{
"term": {
"department_id": 1
}
},
{
"range": {
"price": {
"gte": 0,
"lte": 5000
}
}
}
]
}
}
},
"facets": {
"department_id": {
"terms": {
"field": "department_id"
}
},
"department_name": {
"terms": {
"field": "department_name"
}
},
"price": {
"histogram": {
"field": "price",
"interval": 5000
}
}
}
}
GET /darwin-origin/_mapping?pretty=true
POST darwin-origin/chapter/_search?pretty=true
{
"query": {
"match": {"text": "small mammals"}
},
"fields": ["numeral", "title"],
"highlight": {
"fields": {"text": {"number_of_fragments": 3}}
}
}
POST darwin-origin/chapter/_search?pretty=true
{
"query": {
"match_all": {}
},
"fields": ["_id", "title", "numeral"]
}
POST darwin-origin/chapter/_search?pretty=true
{
"query": {
"match": {"text": {"query": "small mammals", "operator": "and"}}
},
"fields": ["numeral", "title"],
"highlight": {
"fields": {"text": {"number_of_fragments": 3}}
}
}
POST darwin-origin/chapter/_search?pretty=true
{
"query": {
"match_phrase": {"text": "small mammals"}
},
"fields": ["numeral", "title"],
"highlight": {
"fields": {
"text":
{"number_of_fragments": 3}
}
}
}
POST users/user/_search
{"query": {"match": {"username.ngram": "linus"}}}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment