# Parsing query string with custom aggregation, using Search API

**URL:** <https://discuss.elastic.co/t/parsing-query-string-with-custom-aggregation-using-search-api/302200>\
**Category:** Elasticsearch\
**Tags:** language-clients\
**Created:** [April 12, 2022, 9:23am UTC](https://discuss.elastic.co/t/parsing-query-string-with-custom-aggregation-using-search-api/302200 "2022-04-12T09:23:05Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![veggiss](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/veggiss/32/104281_2.png) [@veggiss](https://discuss.elastic.co/u/veggiss)\
**Post date:** [April 12, 2022, 9:23am UTC](https://discuss.elastic.co/t/parsing-query-string-with-custom-aggregation-using-search-api/302200/1 "2022-04-12T09:23:05Z")

</div>

I've installed a plugin to elastic ([GitHub - opendatasoft/elasticsearch-aggregation-geoclustering: An Elasticsearch plugin to aggregate Geo Points in clusters.](https://github.com/opendatasoft/elasticsearch-aggregation-geoclustering)) and I have an endpoint (high level rest client) that takes an ES query body string and builds it with SearchSourceBuilder.

Using kibana, the plugin works fine:

```auto
{
  "size": 0,
  "query": {
    "match_all": {}
  },
  "aggs": {
    "clusters": {
      "geo_point_clustering": {
        "field": "geo.point",
        "zoom": 5
      }
    }
  }
}

```

And I get the expected result.

However, the SearchSourceBuilder have trouble parsing the "geo\_point\_clustering" aggregation

Exception:

```auto
threw exception [Request processing failed; nested exception is ParsingException[Unknown aggregation type [geo_point_clustering]]; nested: NamedObjectNotFoundException[[31:30] unknown field [geo_point_clustering]];] with root cause

```

The exception comes from where the request body is converted into a SearchSourceBuilder

```auto
val searchSourceBuilder = SearchSourceBuilder().timeout(TimeValue(5, TimeUnit.SECONDS))
val searchModule = SearchModule(Settings.EMPTY, false, emptyList())
val xContentRegistry = NamedXContentRegistry(searchModule.namedXContents)
searchSourceBuilder.parseXContent(
  XContentFactory.xContent(XContentType.JSON)
    .createParser(xContentRegistry,
      DeprecationHandler.THROW_UNSUPPORTED_OPERATION, body)
)

```

So my question is (i think) how can I add the custom aggregation type to this parser?

Thanks!

---

<div class="post-metadata">

**Author:** ![RabBit\_BR](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rabbit_br/32/82261_2.png) [@RabBit\_BR](https://discuss.elastic.co/u/RabBit_BR)\
**Post date:** [April 12, 2022, 6:00pm UTC](https://discuss.elastic.co/t/parsing-query-string-with-custom-aggregation-using-search-api/302200/2 "2022-04-12T18:00:08Z")

</div>

Hi.

I dont now if I to help but you can perform this way using query in format json:

> **[Creating API objects from JSON data | Elasticsearch Java API Client \[8.1\] |...](https://www.elastic.co/guide/en/elasticsearch/client/java-api-client/current/loading-json.html#_creating_a_search_request_from_multiple_json_snippets)**

---

<div class="post-metadata">

**Author:** ![veggiss](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/veggiss/32/104281_2.png) [@veggiss](https://discuss.elastic.co/u/veggiss)\
**Post date:** [April 13, 2022, 9:32am UTC](https://discuss.elastic.co/t/parsing-query-string-with-custom-aggregation-using-search-api/302200/3 "2022-04-13T09:32:17Z")

</div>

I should've stated this in the post, but we're on v7.10. I'm also in particular interested in using SearchSourceBuilder. Thanks for the suggestion!

---

<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:** [May 11, 2022, 9:32am UTC](https://discuss.elastic.co/t/parsing-query-string-with-custom-aggregation-using-search-api/302200/4 "2022-05-11T09:32:45Z")

</div>

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