L
L
livemirsi2016-07-01 17:25:34
elasticsearch
livemirsi, 2016-07-01 17:25:34

How to do aggregation?

Good afternoon.
There is an index in elasticsearch, documents have a parameters field that stores an array of elements, elements are ordinary strings.
I'm trying to make a request to find documents in which the parameters array contains, for example, 'elem1' and 'elem2' ([...... ..'elem1', ........'elem2'])
After I have selected them, make them distinct (find out the number of array values ​​in this selection), I do it using aggregation:

aggs: {
  results: {
    filter: {
      terms: {
        parameters: ['elem1', 'elem2']
      }
    },
    terms: {
      field: 'parameters',
      size: 200				            	
    }
  }
}

As a result, I get incorrect results, it seems that the aggregation does not respond to:
filter: {
  terms: {
    parameters: ['elem1', 'elem2']
  }
}

Could you tell me how to organize such a request?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
L
livemirsi, 2016-07-01
@livemirsi

Yes, I made the request a little wrong) Here's how to do a search with the content of the value in the array, followed by aggregation:

aggs: {
  results: {
    filter: {
      bool: {
        must: [
        {
          term: {
            parameters: 'elem1'
          }
        },
        {
          term: {
            parameters: 'elem2'
          }
        }
        ]
      }
    },
    aggs: {
      count:{
        terms: {
          field: 'parameters',
          size: 200				            	
        }				        		
      }		        	
    }
  }
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question