- Mapping
{
"example-profiles" : {
"mappings" : {
"dynamic" : "false",
"properties" : {
"organization" : {
"properties" : {
"enabled" : {
"type" : "boolean"
},
"id" : {
"type" : "keyword"
},
"profileId" : {
"type" : "keyword"
}
}
},
"skills" : {
"type" : "nested",
"properties" : {
"id" : {
"type" : "keyword"
},
"note" : {
"type" : "keyword"
},
"profileSkillId" : {
"type" : "keyword"
},
"skillLevelId" : {
"type" : "keyword"
}
}
}
}
}
}
}
I want to filter on Skill Id and then Aggregate on the Skill Level Id.
When I OR
the Skills , it works fine .
Example Aggregation Query
{
"size": 0,
"aggs": {
"skills.skillLevelId": {
"filter": {
"bool": {
"must": [],
"filter": [
{
"terms": {
"organization.id": [
14770
]
}
}
]
}
},
"aggs": {
"skills.skillLevelId": {
"nested": {
"path": "skills"
},
"aggs": {
"agg": {
"filter": {
"bool": {
"should": [
{"term": {"skills.id": 553}},
{"term": {"skills.id": 426}}
]
}
},
"aggs": {
"agg": {
"terms": {
"field": "skills.skillLevelId"
},
"aggs": {
"profileCounts": {
"reverse_nested": {}
}
}
}
}
}
}
}
}
}
}
}
ResultSet:
"aggregations" : {
"skills.skillLevelId" : {
"meta" : { },
"doc_count" : 102,
"skills.skillLevelId" : {
"doc_count" : 136,
"agg" : {
"doc_count" : 5,
"agg" : {
"doc_count_error_upper_bound" : 0,
"sum_other_doc_count" : 0,
"buckets" : [
{
"key" : "1",
"doc_count" : 5,
"profileCounts" : {
"doc_count" : 3
}
}
]
}
}
}
}
}
Please help how to do an AND
, I have tried MUST
, and other FILTERS , but my result is always 0, even though I have documents like below:
"hits": [
{
"_index" : "stg-profiles-1632487680259",
"_type" : "_doc",
"_id" : "5696966",
"_score" : null,
"_source" : {
"id" : 5696966,
"skills" : [
{
"id" : 553,
"skillLevelId" : 1,
"note" : null,
"profileSkillId" : 73632610
},
{
"id" : 426,
"skillLevelId" : 1,
"note" : null,
"profileSkillId" : 73632596
},
{
"id" : 460,
"skillLevelId" : 1,
"note" : null,
"profileSkillId" : 73632586
},
],
"organization" : [
{
"id" : 14770,
"profileId" : 5696966
}
],
},
"sort" : [
"bogart",
5696966
]
}
...
]