Last active
December 1, 2018 15:58
-
-
Save CharlyJazz/038158bf27ffce50bf49f3e592358a89 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
GET /product/default/_search | |
{ | |
"query": { | |
"term": { | |
"is_active": { | |
"value": true | |
} | |
} | |
} | |
} | |
# La 's' en terms permite usar array | |
GET /product/default/_search | |
{ | |
"query": { | |
"terms": { | |
"tags.keyword": [ | |
"Alcohol", | |
"Wine" | |
] | |
} | |
} | |
} | |
GET /product/default/_search | |
{ | |
"query": { | |
"ids": { | |
"values": [1, 2, 3] | |
} | |
} | |
} | |
GET /product/default/_search | |
{ | |
"query": { | |
"range": { | |
"in_stock": { | |
"gte": 10, | |
"lte": 15 | |
} | |
} | |
} | |
} | |
GET /product/default/_search | |
{ | |
"query": { | |
"range": { | |
"created": { | |
"gte": "01-01-2010", | |
"lte": "15-01-2010", | |
"format": "dd-MM-yyyy" | |
} | |
} | |
} | |
} | |
# Con expresiones matematicas | |
GET /product/default/_search | |
{ | |
"query": { | |
"range": { | |
"created": { | |
"gte": "2010/01/01||-1y-1d/m" | |
} | |
} | |
} | |
} | |
# Con now string como fecha | |
GET /product/default/_search | |
{ | |
"query": { | |
"range": { | |
"created": { | |
"gte": "now-1y-1d/m" | |
} | |
} | |
} | |
} | |
# Usando exist | |
GET /product/default/_search | |
{ | |
"query": { | |
"exists": { | |
"field": "tags" | |
} | |
} | |
} | |
# Usando wildcard | |
GET /product/default/_search | |
{ | |
"query": { | |
"wildcard": { | |
"tags.keyword": { | |
"value": "Ve*ta" | |
} | |
} | |
} | |
} | |
# Usando prefix | |
GET /product/default/_search | |
{ | |
"query": { | |
"prefix": { | |
"tags.keyword": { | |
"value": "Ve" | |
} | |
} | |
} | |
} | |
# Usando rege notation | |
GET /product/default/_search | |
{ | |
"query": { | |
"regexp": { | |
"tags.keyword": { | |
"value": "Veg[a-zA-Z]table" | |
} | |
} | |
} | |
} | |
GET /product/default/_search | |
{ | |
"query": { | |
"range": { | |
"sold": { | |
"lte": 10 | |
} | |
} | |
} | |
} | |
GET /product/default/_search | |
{ | |
"query": { | |
"range": { | |
"sold": { | |
"lte": 10 | |
} | |
} | |
} | |
} | |
GET /product/default/_search | |
{ | |
"query": { | |
"range": { | |
"sold": { | |
"gte": 10, | |
"lte": 30 | |
} | |
} | |
} | |
} | |
GET /product/default/_search | |
{ | |
"query": { | |
"term": { | |
"tags.keyword": "Meat" | |
} | |
} | |
} | |
GET /product/default/_search | |
{ | |
"query": { | |
"terms": { | |
"name": [ | |
"Tomato", | |
"Paste" | |
] | |
} | |
} | |
} | |
GET /product/default/_search | |
{ | |
"query": { | |
"regexp": { | |
"description": { | |
"value": "past?" | |
} | |
} | |
} | |
} | |
GET /product/default/_search | |
{ | |
"query": { | |
"regexp": { | |
"name": { | |
"value": "[0-9]+" | |
} | |
} | |
} | |
} | |
GET /recipe/default/_search | |
{ | |
"query": { | |
"match": { | |
"title": { | |
"query": "pasta spaghetti", | |
"operator": "and" | |
} | |
} | |
} | |
} | |
# Please write a query searching for the sentence "pasta with parmesan and spinach" within the "title" field, simulating that this sentence was entered by a user within a search field. | |
GET /recipe/default/_search | |
{ | |
"query": { | |
"match": { | |
"title": "pasta with parmesan and spinach" | |
} | |
} | |
} | |
GET /recipe/default/_search | |
{ | |
"query": { | |
"match_phrase": { | |
"title": "pasta carbonara" | |
} | |
} | |
} | |
GET /recipe/default/_search | |
{ | |
"query": { | |
"multi_match": { | |
"query": "pasta pesto", | |
"fields": [ | |
"title", | |
"description" | |
] | |
} | |
} | |
} | |
# Compound Queries | |
GET /recipe/default/_search | |
{ | |
"query": { | |
"bool": { | |
"must": [ | |
{ | |
"match": { | |
"ingredients.name": "parmesan" | |
} | |
} | |
], | |
"must_not": [ | |
{ | |
"match": { | |
"ingredients.name": "tuna" | |
} | |
} | |
], | |
"should": [ | |
{ | |
"match": { | |
"ingredients.name": "parsley" | |
} | |
} | |
], | |
"filter": [ | |
{ | |
"range": { | |
"preparation_time_minutes": { | |
"lte": 15 | |
} | |
} | |
} | |
] | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment