Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@nickhoffman
Created November 18, 2011 07:34
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 nickhoffman/31e5846f104fecccd304 to your computer and use it in GitHub Desktop.
Save nickhoffman/31e5846f104fecccd304 to your computer and use it in GitHub Desktop.
Why does sorting fail here?
curl -X PUT 'localhost:9200/test/product/4e725af8349c301b5500002e' -d '{
"name" : "Snoprinsessa Barbie",
"items" : [
{ "name" : "Faux fur-trimmed parka", "properties" : {"color" : "White"} },
{ "name" : "Stud Diamond Ring", "properties" : {"color" : "Clear"} }
]
}'
curl -X GET 'localhost:9200/test/product/_search?pretty=true' -d '{
"sort" : [{ "items.properties.color.orig": {"order": "asc"} }]
}'
{
"took" : 2,
"timed_out" : false,
"_shards" : {
"total" : 5,
"successful" : 4,
"failed" : 1,
"failures" : [ {
"index" : "test",
"shard" : 2,
"status" : 500,
"reason" : "QueryPhaseExecutionException[[test][2]: query[ConstantScore(*:*)],from[0],size[10],sort[<custom:\"items.properties.color.orig\": org.elasticsearch.index.field.data.strings.StringFieldDataType$1@1b61aea>]: Query Failed [Failed to execute main query]]; nested: IOException[Can't sort on string types with more than one value per doc, or more than one token per field]; "
} ]
},
"hits" : {
"total" : 0,
"max_score" : null,
"hits" : [ ]
}
}
curl -X DELETE 'localhost:9200/test'
curl -X PUT 'localhost:9200/test' -d '{
"settings": {
"analysis": {
"filter": {
"edge_ngram": {
"type": "edgeNGram",
"side": "front",
"max_gram": 20,
"min_gram": 1
}
},
"analyzer": {
"ascii_std": {
"type": "custom",
"tokenizer": "standard",
"filter": ["standard", "lowercase", "asciifolding"]
},
"ascii_edge_ngram": {
"type": "custom",
"tokenizer": "standard",
"filter": ["standard", "lowercase", "asciifolding", "edge_ngram"]
}
}
}
}
}'
curl -X GET 'localhost:9200/test/product/_mapping?pretty=true'
{
"product" : {
"properties" : {
"items" : {
"properties" : {
"name" : {
"type" : "string"
},
"properties" : {
"properties" : {
"color" : {
"type" : "multi_field",
"fields" : {
"color" : {
"include_in_all" : true,
"index_analyzer" : "ascii_edge_ngram",
"search_analyzer" : "ascii_std",
"type" : "string"
},
"orig" : {
"include_in_all" : false,
"index" : "not_analyzed",
"type" : "string"
}
}
}
}
}
}
},
"name" : {
"type" : "string"
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment