1
votes

I'm implemented Tire wih elasticsearch. Locally my project runs fine and I have no trouble searching my index. But when I deployed my app to my server I got this error message:

Tire::Search::SearchRequestFailed (500 : {"error":"SearchPhaseExecutionException[Failed to execute phase [query_fetch], total failure; shardFailures {[hDTlT_K_Sl6P5regwKNJyg][articles] [0]: QueryPhaseExecutionException[[articles][0]: query[ConstantScore(NotDeleted(cache(_type:article)))],from[0],size[25],sort[!]: 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]; }]","status":500}):

I believe my articles are stored in my index because I didn't receive any errors creating them. I also tried to run the same query manually with this:

curl -XPOST 'http://localhost:9200/articles/article/_search' -d '{ 
    "sort": [ 
        { 
            "supplier_code": "desc" 
        } 
    ] 
}'

And I got practically the same response:

{"error":"SearchPhaseExecutionException[Failed to execute phase [query_fetch], total failure; shardFailures {[hDTlT_K_Sl6P5regwKNJyg][articles][0]: QueryPhaseExecutionException[[articles][0]: query[ConstantScore(NotDeleted(cache(_type:article)))],from[0],size[10],sort[!]: 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]; }]","status":500}

So can Anybody point me in the right direction? I copied the exact sam config I use on my local machine. So strange it doesn't work on the server.

What am I missing here?

Thanks a lot in advance

EDIT:

I found out that the sort I'm trying to perform is causing the issue. Also that is has something to do with the mapping of my article object to elastic search.

Something with the field I'm trying to sort put on not_analyzed I'm I correct? Do I need to explicitly map all my fields if I map one field only?

1

1 Answers

2
votes

This is the actual issue: Can't sort on string types with more than one value per doc, or more than one token per field. It means one of two things: either you have multiple supplier_code fields per document or the field supplier_code is analyzed by an analyzer the produces multiple tokens (default analyzer would do that for some strings). Elasticsearch can only sort on fields that contains no more than one value per record. So, if you have multiple fields, you need to come up with another sort key or if you have a single field, you need to make it not_analyzed, or use some other analyzer that doesn't produce multiple tokens.