Hello,
I have a mapping like this
posts: {
post: {
properties: {
conversations: {
type: "nested"
properties: {
datetime: {
type: "date"
},
param: {
type: "string"
}
}
}
}
}
}
And a query like this
{
query:{
match_all:[]
},
size:0,
facets:{
matching_conversations:{
nested:"conversations",
facet_filter:{
bool:{
must:[
{
term:{
conversations.param:value
}
}
]
}
},
range:{
field:"conversations.datetime",
ranges:[
{
from:1374444000,
to:1374530399
}
]
}
}
}
}
Basically, I want to know a number of nested fields with a certain value in a specific datetime ranges.
But weirdly, if i filter for a param value 0 and have a data like this
post1:
conversation1: param: 1
conversation2: param: 1
conversation3: param: 0
conversation4: param: 1
post2:
conversation1: param: 0
I should get a count 2 (two conversations with a param value 0), but I get a count 4. I have tested it further and it seems that elasticsearch is basically counting the order of the found conversation. So if the conversation is on the 3th place in the nested array, it gets counted as 3.
Is this an expected behaviour?
When I tried to change the facet to a nested one, I got no result for a change.
facet_filter:{
nested: {
path: "conversations",
query: {
bool:{
must:[
{
term:{
conversations.param:value
}
}
]
}
}
}
},
I was able to get a correct count by creating a nested query with the original facet filter, however I would need the main query to remain non-nested, since I need to filter by parent (post) params.
{
"query": {
"nested": {
"path":"conversations",
"query": {
"match_all":{}
}
},
}
}
Or am I missing something?
Thanks for any info.