Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
curl -XDELETE localhost:9200/test-idx
curl -XPUT localhost:9200/test-idx -d '{
"settings": {
"index": {
"number_of_replicas": 0,
"number_of_shards": 1
}
},
"mappings": {
"doc": {
"properties": {
"filename": {
"type": "string",
"index": "not_analyzed"
}
}
}
}
}'
# Generate random data
for i in {1..100}; do r=$(( RANDOM %= 200 )); n=`printf "%03d" $r`; curl -XPUT localhost:9200/test-idx/doc/$i -d "{\"filename\":\"file$n.abc\"}"; done
curl -XPOST localhost:9200/test-idx/_refresh
echo
echo "=========================="
# Sort using not_analyzed field
curl -s "localhost:9200/test-idx/_search?pretty=true" -d '{
"from": 0,
"size": 10,
"query": {
"match_all": {}
},
"fields": ["filename"],
"sort": [{
"_script": {
"script": "doc[\"filename\"].value",
"type": "string"
}
}]
}' | grep \"sort\"
echo
curl -s "localhost:9200/test-idx/_search?pretty=true" -d '{
"from": 0,
"size": 100,
"query": {
"match_all": {}
},
"fields": ["filename"],
"sort": [{
"_script": {
"script": "doc[\"filename\"].value",
"type": "string"
}
}]
}' | grep \"sort\"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.