Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@pmishev
Created April 28, 2014 15:21
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 pmishev/11375297 to your computer and use it in GitHub Desktop.
Save pmishev/11375297 to your computer and use it in GitHub Desktop.
# Remove old data
curl -XDELETE "http://localhost:9200/index1"
# Create mapping
curl -XPOST localhost:9200/index1/ -d '{
"mappings": {
"people": {
"properties": {
"work_email": {
"type": "string",
"index_name": "email",
"fields": {
"raw": {
"type": "string",
"index": "not_analyzed"
}
}
}
}
}
}
}'
# Create Documents
curl -XPOST "http://localhost:9200/index1/people/" -d '{"work_email":"aaa"}'
curl -XPOST "http://localhost:9200/index1/people/" -d '{"work_email":"bbb"}'
curl -XPOST "http://localhost:9200/index1/people/" -d '{"work_email":"ccc"}'
sleep 1
# Sort results by the analyzed field as named by 'index_name'
# (Works, but I must sort by the non-analyzed field to get correct order)
curl -XPOST "http://localhost:9200/index1/people/_search?pretty=true" -d '
{
"sort": [
{
"email": {
"order": "asc"
}
}
]
}
'
# Sort results by the non-analyzed field
# (Works, but I need to reference the field as email, not as work_email)
curl -XPOST "http://localhost:9200/index1/people/_search?pretty=true" -d '
{
"sort": [
{
"work_email.raw": {
"order": "asc"
}
}
]
}
'
# Sort results by the non-analyzed field, using the field alias
# (This is what I really need, but it gives an error:
# [No mapping found for [email.raw] in order to sort on])
curl -XPOST "http://localhost:9200/index1/people/_search?pretty=true" -d '
{
"sort": [
{
"email.raw": {
"order": "asc"
}
}
]
}
'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment