Query fails via Java client, successful with elasticsearch-head


(Shane Witbeck) #1

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?


(avasilenko) #2

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:

https://gist.github.com/1371153

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?


(Shane Witbeck) #3

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


(Shay Banon) #4

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:

https://gist.github.com/1371479

Thanks


(Shane Witbeck) #5

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.


(mkleen) #6

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.


(Shane Witbeck) #7

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.


(Shay Banon) #8

Use mutli field mapping:
http://www.elasticsearch.org/guide/reference/mapping/multi-field-type.html.

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:

https://gist.github.com/1385933

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.


(Shane Witbeck) #9

Shay, that worked! Thanks for the quick response.


(system) #10