Hi, guys!!!
I want to calculate how much time a user has spent in the game.
I have my documents with fields:
timestamp,
message.
Message field can be 2 different types: "log in" and "log out". Difference in time between "log in" and "log out" is the time my user has spent in my game. Is it possible to calculate the time the user has spent in the game for a month?
As I understand your question
There is not any concept of SUB Searches (like in SQl) I don't think you will be able to do this, This data would have to be processed by the app making the request and not by elastic search. (IE get a list of all login's and then query all the logouts and compare)
You may find this pages of interest, but I think this is more complicated that what your trying to accomplish
http://joelabrahamsson.com/grouping-in-elasticsearch-using-child-documents/
@eperry
But if I have 2 documents (one with"log in"and another with "log out") can I get time between this 2 documents using timestamp? (For example log out.timestamp - log in.timestamp)?
You will probably find this talk by @Mark_Harwood interesting. Here he presents a way of answering these exact questions by indexing your documents in an "entity-centric" (in your case it would be user-centric) way
https://www.elastic.co/elasticon/2015/sf/building-entity-centric-indexes
Also, if you are a Logstash user, you can have a look at this new logstash plugin: https://github.com/logstash-plugins/logstash-filter-aggregate which could help you to generate that prior indexing your doc.
Might help.
@dadoonet
That is a cool idea of a plugin, I will definitely check that out. I presume my "Task_ID" could be a users Jsession id.
@Smasell right comparing 2 documents are not possible (Though maybe you can find a aggregator or as @Dadoonet suggest Merge the Login and logout to one document. At that point you can compare 2 fields with scripted field.
There may be other possibilities but extend outhside the actual Elasticsearch Query Language.