Skip to content

Instantly share code, notes, and snippets.

@mahnunchik
Created May 15, 2013 09:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mahnunchik/5582680 to your computer and use it in GitHub Desktop.
Save mahnunchik/5582680 to your computer and use it in GitHub Desktop.
#!/bin/sh
# Запрос только по тексту, находим 1 запись (Японская AND корпорация)
echo "query_string search:"
curl -XPOST 'http://localhost:9200/testindex/testtype/_search?pretty' -d '{
"sort": [
{
"_id": {
"order": "desc"
}
}
],
"size": 20,
"query": {
"query_string": {
"query": "Японская корпорация",
"default_field": "text",
"default_operator": "AND",
"analyze_wildcard": true
}
}
}' && echo
# Запрос только по координатам, находим 1 запись
echo "geo_bounding_box search:"
curl -XPOST 'http://localhost:9200/testindex/testtype/_search?pretty' -d '{
"sort": [
{
"_id": {
"order": "desc"
}
}
],
"size": 20,
"query": {
"match_all": {}
},
"filter": {
"geo_bounding_box": {
"coordinates": {
"top_left": {
"lat": 4,
"lon": 2
},
"bottom_right": {
"lat": 2,
"lon": 4
}
}
}
}
}' && echo
# Запрос только по дате, находим 1 запись
echo "range search:"
curl -XPOST 'http://localhost:9200/testindex/testtype/_search?pretty' -d '{
"sort": [
{
"_id": {
"order": "desc"
}
}
],
"size": 20,
"query": {
"match_all": {}
},
"filter": {
"range": {
"created": {
"from": "2012-03-01T17:00:00.000Z",
"to": "2012-05-01T17:00:00.000Z"
}
}
}
}' && echo
echo "all fields search:"
curl -XPOST 'http://localhost:9200/testindex/testtype/_search?pretty' -d '{
"sort": [
{
"_id": {
"order": "desc"
}
}
],
"size": 20,
"query": {
"query_string": {
"query": "Японская",
"default_field": "text",
"default_operator": "AND",
"analyze_wildcard": true
}
},
"filter": {
"and": [
{
"geo_bounding_box": {
"coordinates": {
"top_left": {
"lat": 6,
"lon": 4
},
"bottom_right": {
"lat": 4,
"lon": 6
}
}
}
},
{
"range": {
"created": {
"from": "2012-03-01T17:00:00.000Z",
"to": "2012-05-01T17:00:00.000Z"
}
}
}
]
}
}' && echo
# А теперь полный запрос, ещё и с фильтром по _id
echo "all fields and _id search:"
curl -XPOST 'http://localhost:9200/testindex/testtype/_search?pretty' -d '{
"sort": [
{
"_id": {
"order": "desc"
}
}
],
"size": 20,
"query": {
"query_string": {
"query": "Японская",
"default_field": "text",
"default_operator": "AND",
"analyze_wildcard": true
}
},
"filter": {
"and": [
{
"geo_bounding_box": {
"coordinates": {
"top_left": {
"lat": 6,
"lon": 4
},
"bottom_right": {
"lat": 4,
"lon": 6
}
}
}
},
{
"range": {
"created": {
"from": "2012-03-01T17:00:00.000Z",
"to": "2012-06-01T17:00:00.000Z"
}
}
},
{
"range": {
"_id": {
"from": 5
}
}
}
]
}
}' && echo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment