Last active
February 3, 2026 20:23
-
-
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/6a9457ed18e03c54047a7f16ad7ea96b517dfe3a
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 License Version 2.0 (https://www.apache.org/licenses/LICENSE-2.0.txt) | |
| ## 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