Retrieve information about matched words before aggregation

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

Hi,

I tried to use scipt fields but they are not visible from aggregation.

It looks like there is no way to achieve my query.

I was very enthusiastic when I found out how to make my query "all user who went through event "A" then through event "B" " as I realized the power of parent/child relationship and scripted aggregations.
I really hoped it could be possible to make this kind of complex queries on a "match" criteria.
Unfortunatly it seems impossible at the aggregation stage to retreive the information about which word matched a match query.
I'll have to use several queries and deal with results (compare to know if eventA.date<eventB.date etc ...) on my side.

Regards,

Pierre

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.