# Different result from search and aggregation of that search

**URL:** <https://discuss.elastic.co/t/different-result-from-search-and-aggregation-of-that-search/32401>\
**Category:** Elasticsearch\
**Created:** [October 16, 2015, 4:34pm UTC](https://discuss.elastic.co/t/different-result-from-search-and-aggregation-of-that-search/32401 "2015-10-16T16:34:05Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![isaacpm](https://avatars.discourse-cdn.com/v4/letter/i/b9e5f3/32.png) [@isaacpm](https://discuss.elastic.co/u/isaacpm)\
**Post date:** [October 16, 2015, 4:34pm UTC](https://discuss.elastic.co/t/different-result-from-search-and-aggregation-of-that-search/32401/1 "2015-10-16T16:34:05Z")

</div>

Hi,  
I'm getting different results from a search for documents and the same search done with aggregations.  
Here are the searches I'm using:  
Search for documents:

> { "query": {"multi\_match" : {"query": "whatever", "fields": ["name^5", "company", "description"]}}, "from": 0,"size": 12}

Same search, aggregated:

> { "fields": ["categories.raw"], "query": {"filtered" : {"query": {"multi\_match" : {"query": "whatever", "fields": ["name^5", "company", "description"] }}}} , "aggs" : {"categories" : {"terms" : { "field" : "categories.raw" }}}, "size": 0}

I also used the following aggregated query, with the same results as the above aggregated:

> {"query": {"multi\_match": {"query": "whatever","fields": ["name^5","company","description"]}},"aggs": {"categories": {"terms": {"field": "categories.raw"}}},"size": 0}

What I'd like to get is the aggregate of the categories field with the same results as the ones obtained by the search of documents.  
Not sure what I'm missing, but I would expect that the same search gives the same results for an aggregation.

Any ideas?

Thanks,  
Isaac

---

<div class="post-metadata">

**Author:** ![isaacpm](https://avatars.discourse-cdn.com/v4/letter/i/b9e5f3/32.png) [@isaacpm](https://discuss.elastic.co/u/isaacpm)\
**Post date:** [October 18, 2015, 11:42am UTC](https://discuss.elastic.co/t/different-result-from-search-and-aggregation-of-that-search/32401/2 "2015-10-18T11:42:52Z")

</div>

Found the issue, I placed the size value outside of the terms field.  
Once I placed within the terms field, it started working fine.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 5, 2017, 11:44pm UTC](https://discuss.elastic.co/t/different-result-from-search-and-aggregation-of-that-search/32401/3 "2017-07-05T23:44:11Z")

</div>


