Skip to content

Instantly share code, notes, and snippets.

@colinpollock
Created June 12, 2013 08:33
Show Gist options
  • Save colinpollock/5763710 to your computer and use it in GitHub Desktop.
Save colinpollock/5763710 to your computer and use it in GitHub Desktop.
ES demo of document fields only working w/ indexed field.
#
# http://www.elasticsearch.org/guide/reference/modules/scripting/
#
# Create the index
curl -XPOST 'http://localhost:9200/people/' -d '{
"settings" : {
},
"mappings" : {
"person" : {
"properties" : {
"name" : {
"type": "string",
"index": "not_analyzed",
"store": true
},
"age": {
"type": "integer",
"index": "no",
"store": true
}
}
}
}
}'
# Add a doc
curl -XPOST 'http://localhost:9200/people/person' -d '{
"name": "bob",
"age": 31
}'
curl -XGET 'http://localhost:9200/people/person/_search?pretty=true' -d '
{
"query": {
"custom_score": {
"query": {
"term": {
"name": "bob"
}
},
"script": "doc['age'].value"
}
}
}'
# Result is:
{
"error" : "SearchPhaseExecutionException[Failed to execute phase [query], total failure; shardFailures {[izB33BnDTYmONDWVTT7pyw][people][1]: SearchParseException[[people][1]: from[-1],size[-1]: Parse Failure [Failed to parse source [_na_]]]; nested: ElasticSearchParseException[Failed to derive xcontent from org.elasticsearch.common.bytes.ChannelBufferBytesReference@43dd8f24]; }{[izB33BnDTYmONDWVTT7pyw][people][4]: SearchParseException[[people][4]: from[-1],size[-1]: Parse Failure [Failed to parse source [_na_]]]; nested: ElasticSearchParseException[Failed to derive xcontent from org.elasticsearch.common.bytes.ChannelBufferBytesReference@43dd8f24]; }{[izB33BnDTYmONDWVTT7pyw][people][3]: SearchParseException[[people][3]: from[-1],size[-1]: Parse Failure [Failed to parse source [_na_]]]; nested: ElasticSearchParseException[Failed to derive xcontent from org.elasticsearch.common.bytes.ChannelBufferBytesReference@43dd8f24]; }]",
"status" : 500
# Changing the age field to {"index": "not_analyzed"} works (the score is 31, Bob's age).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment