Last active
April 2, 2023 10:10
-
-
Save dacr/fceaac153286a141866ad2994db2e4e3 to your computer and use it in GitHub Desktop.
search for code examples using elasticsearch simple query language / published by https://github.com/dacr/code-examples-manager #a562452c-688c-47c8-a6c4-9cfa27be70a0/4014b1d1ea8b463c5a3ae2350fd5da3e704c826e
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
## summary : search for code examples using elasticsearch simple query language | |
## keywords : bash, elasticsearch, search, code-examples-manager, cem, curl, json, jq, shell | |
## publish : gist | |
## authors : David Crosson | |
## license : Apache NON-AI License Version 2.0 (https://raw.githubusercontent.com/non-ai-licenses/non-ai-licenses/main/NON-AI-APACHE2) | |
## id : a562452c-688c-47c8-a6c4-9cfa27be70a0 | |
## created-on : 2021-04-30T16:45:20Z | |
## managed-by : https://github.com/dacr/code-examples-manager | |
## execution : shell script | |
TARGET=${ELASTIC_URL:-http://127.0.0.1:9200} | |
AUTH="$ELASTIC_USERNAME:$ELASTIC_PASSWORD" | |
query="${@:-hello+world}" | |
generate_query() { | |
cat <<EOF | |
{ | |
"_source":["filename","summary", "created_by", "updated_count", "last_updated"], | |
"size":5, | |
"query": { | |
"query_string": { | |
"query":"$query", | |
"default_operator": "AND" | |
} | |
} | |
} | |
EOF | |
} | |
#echo "$(generate_query)" | |
#curl -s -XGET "$TARGET/cem-*/_search" -H 'Content-Type: application/json' --data "$(generate_query)" | jq | |
curl -u $AUTH -s -XGET "$TARGET/cem-*/_search" -H 'Content-Type: application/json' --data "$(generate_query)" | jq |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment