Filter items of array field with query while aggregating values

Hi!

I ran into a problem for which I can not find an acceptable solution:

Input:
I have index of documents

{
    "profile": {
        "mappings": {
            "properties": {
				...
                "skills": {
                    "type": "text",
                    "fields": {
                        "keyword": {
                            "type": "keyword",
                            "ignore_above": 256
                        }
                    }
                },
				...
        }
    }
}

Where, in fact, "skills" field is array of strings

{
	...
	"skills": [ "skill1", "skill2" ]
	...
}

I need:

  1. Aggregate all unique value of this field
  2. Amount of possible values may be big, so I need paging
  3. Filter aggregated values with match query.

Now I have smth like this:

{
	"aggs": {
		"skills": {
			"composite": {
				"size": 10,
				"sources": [{
						"skills_sub": {
							"terms": {
								"field": "skills.keyword"
							}
						}
					}
				]
			}
		}
	},
	"query": {
		"bool": {
			"should": [{
					"match": {
						"skills": {
							"query": "value"
						}
					}
				}
			]
		}
	},
	"size": 0
}

It almost matches my requirements:

  1. It aggregates unique values
  2. I have "After" and "Size"
  3. It returns values, that match query. BUT it returns ALL values from array if any matches

So, if doc has field "skills" with values: "value1", "value2". And I request for "value1", I'll got both of them.

So, what I need to do, to override this behavior?

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