id property not created in the ElasticSearch index, sorting not possible ?

402 views
Skip to first unread message

Ondrej Pačay

unread,
Feb 4, 2017, 1:11:45 PM2/4/17
to Ebean ORM
Hello, 

let's say I have a model:

@DocStore(doc = "id")
public class Model{
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
protected Long id;
...
}

The DocStore annotation does not create a property id in the ElasticSearch index. 

When requesting an ordered list from the ES  using query.order("id") the following json is produced:
json:{"size":1000,"sort":[{"id":{"order":"asc"}}],"query":{"match_all":{}}}

and ES query fails:
Caused by: java.io.IOException: Unhandled response code 400 
body:{"error":{"root_cause":[{"type":"search_parse_exception",
"reason":"No mapping found for [id] in order to sort on"}],
"type":"search_phase_execution_exception","reason":"all shards failed",
"phase":"query","grouped":true,
"failed_shards":[{"shard":0,"index":"model_v1","node":"TYGwdbCZQNiwVM2I2Abn4w",
"reason":{"type":"search_parse_exception",
"reason":"No mapping found for [id] in order to sort on"}}]},"status":400}

Is there a way to include the model id into the index?
Sometimes it can be useful(needed) for paged queries, correct?
Or is there another way to sort the results if no other field is unique?


Thanks, Ondrej 

Rob Bygrave

unread,
Feb 8, 2017, 4:42:59 AM2/8/17
to ebean@googlegroups
> The DocStore annotation does not create a property id in the ElasticSearch index.

That is correct in that the @Id property is stored as the ElasticSearch _id value (and at this stage we don't have a nice simple mechanism to duplicate the @Id value as a 'normal field' in the index).




> Is there a way to include the model id into the index?

Not currently no (which is issue that I haven't hit myself but yes I can see people wanting to do this).



> Sometimes it can be useful(needed) for paged queries, correct?

Well, we can't easily go "order by id" or "order by name, id" ... and especially when @Id maps to a numeric type (Long, Integer) that could be useful.



> Or is there another way to sort the results if no other field is unique?

I'm not sure exactly what Elastic does in those cases (but it does have _id it can use internally for paging etc) so something to look at there.



I have logged this as:
https://github.com/ebean-orm/ebean-elastic/issues/23 - Ability to map @Id property to a field in the index (other than _id)



--

---
You received this message because you are subscribed to the Google Groups "Ebean ORM" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ebean+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages