Hi guys,
I'm new to elasticsearch so I hope I used the right terms and that my explanations are clear.
Please tell me if the title is unclear (and sorry for bad english)
I have this schema :
{
"myindex" : {
"mappings" : {
"information" : {
"_parent" : {
"type" : "user"
},
"_routing" : {
"required" : true
},
"properties" : {
"event" : {
"type" : "keyword"
},
"date" : {
"type" : "date"
}
}
}
}
}
}
{
"myindex" : {
"mappings" : {
"user" : {
"properties" : {
"name" : {
"type" : "keyword"
}
}
}
}
}
}
I'm trying to make a query like "all user who went through event "A" then through event "B" " :
So I did this :
curl -XPOST 'localhost:9200/myindex/information/_search?pretty' -d '
{
"query": {
"bool": {
"must": [{
"has_parent" : {
"parent_type" : "user",
"query" : {
"bool": {
"must": [{
"has_child" : {
"type" : "information",
"query" : {
"term" : {
"event" : "A"
}
}
}
},{
"has_child" : {
"type" : "information",
"query" : {
"term" : {
"event" : "B"
}
}
}
}]
}
}
}
},{
"bool": {
"should": {
"term": {
"event": "A"
}
},
"should": {
"term": {
"event": "B"
}
}
}
}]
},
"aggs": {
"isok": {
"scripted_metric": {
"init_script" : "params.myctx.compute_map = [:];params._agg.listusers = [];",
"map_script" : {
"lang" : "groovy",
"file" : "myscript"
},
"params": {
"_agg": {},
"myctx": {},
"firstCrit" : "A",
"secdCrit" : "B"
}
}
}
}
}
}'
I get all the "informations" hits about event "A" or event "B" from users who went through event A and through event B
When I have all these hits I aggregate with my script "myscript", where I fill a double map like
map[user.name][information.event]=information.date (for each user, I try to find the oldest event A, the newest event B and I compare to know if eventA.date<eventB.date etc ....)
And it works fine !
but actually the "event" field is not a keyword field but a text.
The query is the same, I just replace "term" with "match" but I can't make my aggregation anymore because when my script is executed for each hit from the query, I miss the event.
I know the current hit contains A or B (or both) but I don't know which.
I can't access the "event" field because it's a text field so I lost the information about "why this hit has been selected" before the aggregation phase.
Is there a way to retreive this information from my aggregation script ?
Could I pass the information on which word(s) matched before the aggregation ?
Thank in advance for your help,
Regards,
Pierre