Created
April 28, 2014 15:21
-
-
Save pmishev/11375297 to your computer and use it in GitHub Desktop.
This file contains 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
# 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