Problem with sorting using an analyzed field


(Enrique Medina Montenegro) #1

Hi,

Why cannot I sort by a field which is analyzed? It should make sense to
analyze a "name" field to index products and also be able to sort by "name"
when getting the search results, agree?

{

"from" : 0, size: 100,

"sort" : { "nombre" : "desc" },

"query" : {

"fuzzy" : { "nombre" : "lacie", "descripcion" : "lacie" }

}

}

I get the error:

sort[<custom:"nombre":
org.elasticsearch.index.field.data.strings.StringFieldDataType$1@46176578>
!]: 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]; }]"}]

Thanks.


(Shay Banon) #2

You can use multi field mapping, with the "original" being analyzed, and one named "sortable" to have it not_analyzed.
On Thursday, February 3, 2011 at 4:53 PM, Enrique Medina Montenegro wrote:

Hi,

Why cannot I sort by a field which is analyzed? It should make sense to analyze a "name" field to index products and also be able to sort by "name" when getting the search results, agree?

{
"from" : 0, size: 100,
"sort" : { "nombre" : "desc" },
"query" : {
"fuzzy" : { "nombre" : "lacie", "descripcion" : "lacie" }
}
}

I get the error:

sort[<custom:"nombre": org.elasticsearch.index.field.data.strings.StringFieldDataType$1@46176578>!]: 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]; }]"}]

Thanks.


(system) #3