Query fails via Java client, successful with elasticsearch-head

Using ES 0.17.9, the following query is successful if I execute using the
elasticsearch-head web ui, but fails when using the Java client:

I get the following ShardSearchFailure:

sort[<custom:"owner.username":
org.elasticsearch.index.field.data.strings.StringFieldDataType$1@173aa68>!]:
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];

The field in question (owner.username) should only have a single value.

Any suggestions on why I'm getting inconsistent results and what I can do
to fix?

Hello Shane,

Please show your mapping for this index type. Are you sure "owner.username"
is not tokenized?

Regards,
Alexandr Vasilenko

2011/11/16 Shane Witbeck shane@digitalsanctum.com

Using ES 0.17.9, the following query is successful if I execute using the
elasticsearch-head web ui, but fails when using the Java client:

ES query failure · GitHub

I get the following ShardSearchFailure:

sort[<custom:"owner.username":
org.elasticsearch.index.field.data.strings.StringFieldDataType$1@173aa68>!]:
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];

The field in question (owner.username) should only have a single value.

Any suggestions on why I'm getting inconsistent results and what I can do
to fix?

I don't have a mapping per se, since I'm letting ES do it at the time of
index. Here's the gist of the content builder:

Thanks

You probably need to set the username to be not_analyzed in the mapping for
it. There isn't a different between using the Java API and the REST API.

On Wed, Nov 16, 2011 at 11:30 PM, Shane Witbeck shane@digitalsanctum.comwrote:

I don't have a mapping per se, since I'm letting ES do it at the time of
index. Here's the gist of the content builder:

content builder for thread · GitHub

Thanks

Thanks. How would I set username to be not_analyzed using the Java API? I
assume this needs to be done at the time of indexing.

Hello,

you need to put a mapping before the indexing and this would look in
java something like:

JsonXContent
    .contentBuilder
    .startObject
      .startObject("Foo")
        .startObject("properties")
          .startObject("username")
             .field("type", "string")
             .field("index", "not_analyzed")
           .endObject
         .endObject
       .endObject
     .endObject

and then you can use
org.elasticsearch.client.Requests.putMappingRequest to send the
xcontent to the server.

Michael

On Nov 17, 2:57 pm, Shane Witbeck sh...@digitalsanctum.com wrote:

Thanks. How would I set username to be not_analyzed using the Java API? I
assume this needs to be done at the time of indexing.

Thanks for the replies. Unfortunately I'm still not able to resolve this.
Shay's suggestion of adding "not_analyzed" to the mapping for username
works for the sort but doesn't allow the field to be searchable. Since my
last post I'm now creating an explicit mapping shown here:

As before, if I try to sort on the owner.ownerUsername field, I get the
following error:

SEARCH FAILURE: status=INTERNAL_SERVER_ERROR,
reason=QueryPhaseExecutionException[[threads][1]:
query[ConstantScore(org.elasticsearch.common.lucene.search.OrFilter@3d0d96f)],from[0],size[25],sort[<custom:"owner.ownerUsername":
org.elasticsearch.index.field.data.strings.StringFieldDataType$1@709d70b4>!]:
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];

What do I need to do in order to have this field searchable AND sortable?

Thanks again.

Use mutli field mapping:
Elasticsearch Platform — Find real-time answers at scale | Elastic.

On Tue, Nov 22, 2011 at 5:30 PM, Shane Witbeck shane@digitalsanctum.comwrote:

Thanks for the replies. Unfortunately I'm still not able to resolve this.
Shay's suggestion of adding "not_analyzed" to the mapping for username
works for the sort but doesn't allow the field to be searchable. Since my
last post I'm now creating an explicit mapping shown here:

ES thread mapping · GitHub

As before, if I try to sort on the owner.ownerUsername field, I get the
following error:

SEARCH FAILURE: status=INTERNAL_SERVER_ERROR,
reason=QueryPhaseExecutionException[[threads][1]:
query[ConstantScore(org.elasticsearch.common.lucene.search.OrFilter@3d0d96f)],from[0],size[25],sort[<custom:"owner.ownerUsername":
org.elasticsearch.index.field.data.strings.StringFieldDataType$1@709d70b4>!]:
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];

What do I need to do in order to have this field searchable AND sortable?

Thanks again.

Shay, that worked! Thanks for the quick response.