Below is the data sample of a single record in my Index:
{
"_index" : "test_index",
"_type" : "_doc",
"_id" : "49605102905391763685971719283371021096086998966740189186",
"_score" : 2.8858113,
"_source" : {
"properties" : {
"activity" : [
{
"activityId" : 39,
"actionVersion" : 2,
"actionIdx" : 3
},
{
"activityId" : 39,
"actionVersion" : 2,
"actionIdx" : 4
},
{
"activityId" : 39,
"actionVersion" : 2,
"actionIdx" : 5
},
{
"activityId" : 42,
"actionVersion" : 2,
"actionIdx" : 3
},
{
"activityId" : 42,
"actionVersion" : 2,
"actionIdx" : 4
},
{
"activityId" : 42,
"actionVersion" : 2,
"actionIdx" : 5
}
]
}
}
}
I want to filter results based on activitiyId 42 and actionIdx 3. I'm using below query trying to get results.
{"size":-1,
"query": {
"bool": {
"should": {
"bool": {
"must": [
{
"match": {
"activityId": 42
}
},
{
"match": {
"actionIdx": 3
}
}
]
}
}
}
}
}
I'm getting the records that contain activityid 42 and actionidx 3 but my requirement is to have records that contain activity 42 and actionidx 3 in the same object. Below are my results with above search query:
"activity" : [
{
"activityId" : 39,
"actionVersion" : 2,
"actionIdx" : 2
},
{
"activityId" : 28,
"actionVersion" : 2,
"actionIdx" : 3
},
{
"activityId" : 42,
"actionVersion" : 2,
"actionIdx" : 2
},
{
"activityId" : 41,
"actionVersion" : 2,
"actionIdx" : 3
}
]
My expected output to be:
"activity" : [
{
"activityId" : 39,
"actionVersion" : 2,
"actionIdx" : 2
},
{
"activityId" : 28,
"actionVersion" : 2,
"actionIdx" : 3
},
{
"activityId" : 42,
"actionVersion" : 2,
"actionIdx" : 3
}
]
Here's is the mapping index. Activity is not nested
"properties" : {
"properties" : {
"activity" : {
"properties" : {
"actionIdx" : {
"type" : "long"
},
"actionVersion" : {
"type" : "long"
},
"activityId" : {
"type" : "long"
}
}
}
}
}