Last active
February 25, 2021 21:11
-
-
Save sjb9774/152fb76512539dd5b45e273060470f44 to your computer and use it in GitHub Desktop.
ElasticSearch CURL Commands
This file contains 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
ES_HOST='elasticsearch-host' # for example 127.0.0.1 | |
ES_PORT='elasticsearch-port' # default 9200 | |
# get indices | |
curl $ES_HOST:$ES_PORT/_cat/indices | |
ES_INDEX='index-name' | |
# get first 5 results from empty | |
curl $ES_HOST:$ES_PORT/$ES_INDEX/_search | jq . | |
# get first 1000 results from index | |
curl $ES_HOST:$ES_PORT/$ES_INDEX/_search?size=1000 | jq . | |
# search with query | |
curl $ES_HOST:$ES_PORT/$ES_INDEX/_search -H 'Content-type: application/json' -d '{"query":{"query_string":{"query":"search-query"}}}' | jq . | |
# search with query and return a specific field (example, sku) from the results | |
curl $ES_HOST:$ES_PORT/$ES_INDEX/_search -H 'Content-type: application/json' -d '{"query":{"query_string":{"query":"search-query"}}}' | jq .hits.hits[]._source.sku | |
# advanced search | |
curl $ES_HOST:$ES_PORT/$ES_INDEX/_search -H 'Content-type: application/json' -X POST -d '{"query":{"bool":{"must":[{"term":{"indexed_attribute_code":{"value":"attribute_value","boost":1.00}}}]}}}' | jq . | |
# wildcard search | |
curl -X GET $ES_HOST:$ES_PORT/$ES_INDEX/_search -H 'Content-type: application/json' -d '{"query":{"wildcard":{"my_field":{"value":"*somevalue*", "boost":1.0,"rewrite":"constant_score"}}}}' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment