Sorting with JAVA Api


(samCougars) #1

All
I'm indexing on two fields title and abbreviation. When I do a search I want to sort the result on title or abbreviation. Both the fields can have multi text values like title can "Harry Potter And Adventures" or abbreviation can be "HP AD And War".
While during search, if I only add sort as (searchRequestBuilder.addSort("title",SearchOrder.ASC)) then it gaves me an error saying that "Can't sort on string types with more than one value per doc, or more than one token per field". I know it because my indexed field "title" is "not_analyzed". I'm creating index as
client.prepareIndex("elasticSearch", "myFields", "1000").setSource(myContentBuilder()).execute().actionGet().

And myContentBuilder() creates a XcontentBuilder like
XContentBuilder myContentBuilder()
{
Map myValues = new HashMap();
myValues.put("title","Harry Potter And Adventures");

myValues.put("abbreviation", "HP AD And War");
XContentBuilder builder = XContentFactory.jsonBuilder().startObject().startObject("title").field("index", "not_analyzed").field("type", "string").endObject().endObject();
return builder.map(myValues);
}

I think there is some issues w/ my XConterBuilder (" XContentBuilder builder = XContentFactory.jsonBuilder().startObject().startObject("title").field("index", "not_analyzed").field("type", "string").endObject().endObject()") but I can't think of any issue on it. It does not throw an error while creating an index but when I do a search it still throws "Can't sort on string types with more than one value per doc, or more than one token per field".
Can anyone think of the issue while I'm creating builder to achieve sorting on title?
Thank you
Satish


(system) #2