Skip to content

Instantly share code, notes, and snippets.

@dacr
Last active April 2, 2023 10:10
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 dacr/fceaac153286a141866ad2994db2e4e3 to your computer and use it in GitHub Desktop.
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
## 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