I'm trying to sort documents based on a field named "sortableSubject" (not analyzed, type string).
But even though it's not analyzed, it throws the following exception:
"ReduceSearchPhaseException: Failed to execute phase [fetch], [reduce] ; shardFailures {[1][1][4]: QueryPhaseExecutionException[[1][4]: query[+(body:body* | subject:body*)],from[0],size[5000],sort[<custom:"sortableSubject": org.elasticsearch.index.field.data.strings.StringFieldDataType$1@14637eb>!]: 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]; }{[1][1][0]: QueryPhaseExecutionException[[1][0]: query[+(body:body* | subject:body*)],from[0],size[5000],sort[<custom:"sortableSubject": org.elasticsearch.index.field.data.strings.StringFieldDataType$1@1b72b99>!]: 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]; }{[1][1][3]: QueryPhaseExecutionException[[1][3]: query[+(body:body* | subject:body*)],from[0],size[5000],sort[<custom:"sortableSubject": org.elasticsearch.index.field.data.strings.StringFieldDataType$1@547ea3>!]: 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]; }{[1][1][1]: QueryPhaseExecutionException[[1][1]: query[+(body:body* | subject:body*)],from[0],size[5000],sort[<custom:"sortableSubject": org.elasticsearch.index.field.data.strings.StringFieldDataType$1@8f7cf4>!]: 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]; }{[1][1][2]: QueryPhaseExecutionException[[1][2]: query[+(body:body* | subject:body*)],from[0],size[5000],sort[<custom:"sortableSubject": org.elasticsearch.index.field.data.strings.StringFieldDataType$1@1015d59>!]: 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]; }
Am I missing something ? Can't we sort documents on a string of many words ?
subject:body*)],from[0],size[5000],sort[<custom:"sortableSubject":
org.elasticsearch.index.field.data.strings.StringFieldDataType$1@14637eb
>!]:
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]; }{[1][1][0]: QueryPhaseExecutionException[[1][0]:
query[+(body:body*
|
subject:body*)],from[0],size[5000],sort[<custom:"sortableSubject":
org.elasticsearch.index.field.data.strings.StringFieldDataType$1@1b72b99
>!]:
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]; }{[1][1][3]: QueryPhaseExecutionException[[1][3]:
query[+(body:body*
|
subject:body*)],from[0],size[5000],sort[<custom:"sortableSubject":
org.elasticsearch.index.field.data.strings.StringFieldDataType$1@547ea3
>!]:
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]; }{[1][1][1]: QueryPhaseExecutionException[[1][1]:
query[+(body:body*
|
subject:body*)],from[0],size[5000],sort[<custom:"sortableSubject":
org.elasticsearch.index.field.data.strings.StringFieldDataType$1@8f7cf4
>!]:
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]; }{[1][1][2]: QueryPhaseExecutionException[[1][2]:
query[+(body:body*
|
subject:body*)],from[0],size[5000],sort[<custom:"sortableSubject":
org.elasticsearch.index.field.data.strings.StringFieldDataType$1@1015d59
>!]:
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]; }
Am I missing something ? Can't we sort documents on a string of many words
?
This was made while unit testing (local node) and I just realized the mapping wasn't really put, so default mapping was used I guess (the field was then analyzed and cause problem when I was sorting on this field).
hi,cgascon,i has the some problem,can you tall me how do you fixed it?thank you!
Hi yin weifeng,
The problem was the mapping.
Here is the mapping I have now (I use two properties), please notice I've copied this code from java and removed some backslash etc so there may be some syntax errors.
When you search by "you" you will get 2 hits, but the original field
doesn't exist any longer, it's has been split into occurences by token. How
do you sort then ?
You can sort by score : the document that has the highest tokens count
comes first (call it ranking, pertinence, whatever).
That's the reason why one can not apply lexicographic sort on ANALYZED
fields, NON ANALYZED ones can.
There are some workarounds : store 2 versions of your field, one that is
analyzed, the other one that is not, and sort by the one that is not
analyzed.
This is exactly what *multifield *does.
Apache, Apache Lucene, Apache Hadoop, Hadoop, HDFS and the yellow elephant
logo are trademarks of the
Apache Software Foundation
in the United States and/or other countries.