Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

This article will give a few examples of doing direct-to-Elasticsearch queries. This is normally not necessary and not advised as queries should be done through the Swarm Search API.

Preparation

  • Set a Swarm Node IP as SCSP_HOST, Elasticsearch IP and the Elasticsearch Index variables. These presume the Support tools are installed at /root/dist

Code Block
languagebash
export SCSP_HOST=<any Swarm node>
export ESIP=$(python /root/dist/platform-get-default-search-feed-ip.py $SCSP_HOST | awk '{ print $1 }')
export ESINDEX=index_$(python /root/dist/platform-get-default-search-index-name.py $SCSP_HOST)

Calls direct to ES

ES information by stream name

Code Block
languagebash
FILENAME=<filename> && curl -s "$ESIP:9200/$ESINDEX/_search?q=stype:NAMED+AND+name:$FILENAME&pretty" | jq  -r '.hits.hits[]'
  • This will return all named streams by that name across buckets/ domains. You can delineate by bucket or domain id as seen in other examples.

ES information by etag

Code Block
languagebash
ETAG=<etag> && curl -s "$ESIP:9200/$ESINDEX/_search?pretty&q=etag:$ETAG" | jq '.hits.hits[]'

Get bucket name, etag, and tmBorn by bucket name

  • This might be handy for recreating a recently deleted bucket

Code Block
BUCKETNAME=<bucket name>;curl -s "$ESIP:9200/$ESINDEX/_search?q=stype:BUCKET+AND+name:$BUCKETNAME"  | jq -r '.hits.hits[]._source | "\(.name), \(.etag), \(.tmBorn), \(.contextid)"'

Get Domain id

from Swarm

Code Block
languagebash
DOMAIN=<domain name> && curl -sIL $SCSP_HOST?domain=$DOMAIN | grep ^Etag^Castor-System-Alias | awk '{ print $2 }' | sed 's/"//g'

from ES directly

Code Block
languagebash
DOMAIN=domain-for-versioning<domain name> && curl -s "$ESIP:9200/$ESINDEX/_search?q=stype:DOMAIN+AND+name:$DOMAIN&pretty" | jq -r '.hits.hits[]._source.etagid'

Get Bucket id (context id)

from Swarm by domain name

Code Block
languagebash
BUCKET=<bucket name> && DOMAIN=<domain name> && curl -sIL "$SCSP_HOST/$BUCKET?domain=$DOMAIN" | grep ^Etag^Castor-System-Alias | awk '{ print $2 }' | sed 's/"//g'

from ES directly- by domain id

Code Block
languagebash
BUCKET=<bucket name> && DOMAINID=<domainid> && curl -s "$ESIP:9200/$ESINDEX/_search?q=domainid:$DOMAINID+AND+stype:BUCKET+AND+name:$BUCKET&pretty" | jq  -r '.hits.hits[]._source.etag'
  • You can remove the name:domain-for-versioning if you know the bucket name is unique among domains. You can leave it off if you aren't sure but might get multiple results to sort through.

id'

Stream count by bucket (context id)

Code Block
languagebash
CONTEXTID=<contextid> && curl -s -XPOST -H "Content-Type: application/json" --data-binary '{"query":{"bool":{"must":[{"match":{"contextid":"'"$CONTEXTID"'"}}]}}}' "$ESIP:9200/$ESINDEX/_count" | jq '.count'

Streams by bucket (context id)

Code Block
BUCKETID=<contextid) &&curl -s "$ESIP:9200/$ESINDEX/_search?q=stype:NAMED+AND+contextid:$BUCKETID&pretty";

Stream count by Domain (domain id)

Code Block
languagebash
DOMAINID=<domainid> && curl -s -XPOST -H "Content-Type: application/json" --data-binary '{"query":{"bool":{"must":[{"match":{"domainid":"'"$DOMAINID"'"}}]}}}' "$ESIP:9200/$ESINDEX/_count" | jq '.count'