Can't sort on string types with more than one value per doc, or more than one token per field

Hello,

I've tried these basic curl commands from elasticsearch api on a clean
elasticsearch version 17.0:

curl -XPUT 'http://localhost:9200/twitter/tweet/7' -d '{
"user" : "Florin Hello",
"post_date" : "2010-11-15 14:12:12",
"message" : "sure"
}'

curl -XPOST 'http://localhost:9200/twitter/tweet/_search' -d '{
"sort": [
{
"user": "desc"
}
]
}'

the sort command failed with error:
{"took":3,"timed_out":false,"_shards":{"total":5,"successful":
4,"failed":1,"failures":[{"index":"twitter","shard":
3,"reason":"QueryPhaseExecutionException[[twitter][3]:
query[ConstantScore(:)],from[0],size[10],sort[<custom:"user":
org.elasticsearch.index.field.data.strings.StringFieldDataType
$1@8d9b22>!]: 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":[]}}

Is there a way to force ElasticSearch to sort over field "user" ?

The field user by default gets analyzed and broken down into one or more
tokens. If it gets broken down into more than one token, then you can't
really sort on it. If you want to sort on it, you either need to set it i(in
the mappings) as not analyzed (see
http://www.elasticsearch.org/guide/reference/mapping/core-types.html), or
use multi field mapping to have it both analyzed and not analyzer (see:
http://www.elasticsearch.org/guide/reference/mapping/multi-field-type.html).

On Tue, Jul 26, 2011 at 11:56 AM, flgor c7florin@gmail.com wrote:

Hello,

I've tried these basic curl commands from elasticsearch api on a clean
elasticsearch version 17.0:

curl -XPUT 'http://localhost:9200/twitter/tweet/7' -d '{
"user" : "Florin Hello",
"post_date" : "2010-11-15 14:12:12",
"message" : "sure"
}'

curl -XPOST 'http://localhost:9200/twitter/tweet/_search' -d '{
"sort": [
{
"user": "desc"
}
]
}'

the sort command failed with error:
{"took":3,"timed_out":false,"_shards":{"total":5,"successful":
4,"failed":1,"failures":[{"index":"twitter","shard":
3,"reason":"QueryPhaseExecutionException[[twitter][3]:
query[ConstantScore(:)],from[0],size[10],sort[<custom:"user":
org.elasticsearch.index.field.data.strings.StringFieldDataType
$1@8d9b22>!]: 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":[]}}

Is there a way to force ElasticSearch to sort over field "user" ?

The fact that the "index" is set as "not_analyzed" comes with any
drawback?

Yes, this means you can only match on exact matches on that specific field.
For example, term/text query against Florian will not work, as well as
username:Florian

On Tue, Jul 26, 2011 at 1:04 PM, flgor c7florin@gmail.com wrote:

The fact that the "index" is set as "not_analyzed" comes with any
drawback?

another question about matching:

if i run this exemple:
curl -XPOST 'http://localhost:9200/twitter/tweet/_search' -d '{
"query": {
"text": {
"message" : "surae"
}
}
}'

i'm quering for the word "surae" where i have in DB "sure", using the
above command, and i get 0 total results.
Is it possible to make elasticSearch to return the item with "sure"
message?

From mapping i guess all my terms are analized: "tweet" : {
"properties" : {
"message" : {
"type" : "string"
},
"user" : {
"type" : "string"
},
"post_date" : {
"type" : "string"
}
}

Thanks for help

You can use different analysis process for the field, for example, use
ngrams to index the field, or different stemmers. Another option is to use
fuzzy queries, but its slower...

On Tue, Jul 26, 2011 at 3:11 PM, flgor c7florin@gmail.com wrote:

another question about matching:

if i run this exemple:
curl -XPOST 'http://localhost:9200/twitter/tweet/_search' -d '{
"query": {
"text": {
"message" : "surae"
}
}
}'

i'm quering for the word "surae" where i have in DB "sure", using the
above command, and i get 0 total results.
Is it possible to make elasticSearch to return the item with "sure"
message?

From mapping i guess all my terms are analized: "tweet" : {
"properties" : {
"message" : {
"type" : "string"
},
"user" : {
"type" : "string"
},
"post_date" : {
"type" : "string"
}
}

Thanks for help

I tried with multi_field but still getting the error: "Can't sort on string types with more than one value per doc, or more than one token per field". Any thoughts?

curl -XPUT http://localhost:9200/twitter

curl -XPUT http://localhost:9200/twitter/tweet/_mapping -d '{
"tweet" : {
"properties" : {
"user" : {
"type" : "multi_field",
"fields" : {
"user" : {"type" : "string", "index" : "analyzed"},
"untouched" : {"type" : "string", "index" : "not_analyzed"}
}
}
}
}
}'

curl -XPUT 'http://localhost:9200/twitter/tweet/7' -d '{
"user" : "Florin Hello",
"post_date" : "2010-11-15 14:12:12",
"message" : "sure"
}'

curl -XPOST 'http://localhost:9200/twitter/tweet/_search' -d '{
"sort": [
{
"user": "desc"
}
]
}'

{"took":5,"timed_out":false,"_shards":{"total":5,"successful":4,"failed":1,"failures":[{"index":"twitter","shard":3,"status":500,"reason":"RemoteTransportException[[Marvel Man][inet[/192.168.101.54:9301]][search/phase/query]]; nested: QueryPhaseExecutionException[[twitter][3]: query[ConstantScore(NotDeleted(cache(_type:tweet)))],from[0],size[10],sort[<custom:"user": org.elasticsearch.index.field.data.strings.StringFieldDataType$1@1248513>!]: 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":[]}}