# Structure for query with multiple sub queries with the same structure but different parameters

**URL:** <https://discuss.elastic.co/t/structure-for-query-with-multiple-sub-queries-with-the-same-structure-but-different-parameters/297939>\
**Category:** Elasticsearch\
**Created:** [February 22, 2022, 5:51pm UTC](https://discuss.elastic.co/t/structure-for-query-with-multiple-sub-queries-with-the-same-structure-but-different-parameters/297939 "2022-02-22T17:51:33Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![GavinBeattie](https://avatars.discourse-cdn.com/v4/letter/g/5f9b8f/32.png) [@GavinBeattie](https://discuss.elastic.co/u/GavinBeattie)\
**Post date:** [February 22, 2022, 5:51pm UTC](https://discuss.elastic.co/t/structure-for-query-with-multiple-sub-queries-with-the-same-structure-but-different-parameters/297939/1 "2022-02-22T17:51:33Z")

</div>

I am trying to analyse speed exceedances along a route, and what I would like is a query that returns all results together (all speed exceedances), which is the result of individual section by section queries (because each section has a different speed limit). Something like the following:

(section: 1 AND speed\_limit 1) OR  
(section: 2 AND speed\_limit 2) OR ...  
(section: i AND speed\_limit i) OR  
Where i is quite large, maybe 1000 to cover the whole network map. Is there any harm in just combining large numbers of small queries? Is there a better way to structure them? Are there any specialist queries that could help simplify?

---

<div class="post-metadata">

**Author:** ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)\
**Post date:** [February 23, 2022, 11:53am UTC](https://discuss.elastic.co/t/structure-for-query-with-multiple-sub-queries-with-the-same-structure-but-different-parameters/297939/2 "2022-02-23T11:53:54Z")

</div>

Hey,

this is one is tough to answer without knowing more about the data model. In general, there is a limit of the number of bool clauses, see [Search settings | Elasticsearch Guide [8.0] | Elastic](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-settings.html)

Would it be possible to populate data prior to indexing or use a runtime field to expose the information of speeding?

--Alex

---

<div class="post-metadata">

**Author:** ![GavinBeattie](https://avatars.discourse-cdn.com/v4/letter/g/5f9b8f/32.png) [@GavinBeattie](https://discuss.elastic.co/u/GavinBeattie)\
**Post date:** [February 23, 2022, 1:50pm UTC](https://discuss.elastic.co/t/structure-for-query-with-multiple-sub-queries-with-the-same-structure-but-different-parameters/297939/3 "2022-02-23T13:50:54Z")

</div>

Probably not prior to indexing because the speed limits can change through time, I think runtime might be too much of a performance hit. We might just need to try with a large number of search settings. We did wonder about storing the results of the individual queries in a separate index but this would take away from the live nature of the system. Further thoughts welcome.

---

<div class="post-metadata">

**Author:** ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)\
**Post date:** [February 24, 2022, 8:50am UTC](https://discuss.elastic.co/t/structure-for-query-with-multiple-sub-queries-with-the-same-structure-but-different-parameters/297939/4 "2022-02-24T08:50:13Z")

</div>

If the speed limits can change over time, maybe an [enrich processor](https://www.elastic.co/guide/en/elasticsearch/reference/8.0/enrich-processor.html) might be an interesting option? See [Set up an enrich processor | Elasticsearch Guide [8.0] | Elastic](https://www.elastic.co/guide/en/elasticsearch/reference/8.0/enrich-setup.html) for more information

---

<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:** [March 24, 2022, 8:50am UTC](https://discuss.elastic.co/t/structure-for-query-with-multiple-sub-queries-with-the-same-structure-but-different-parameters/297939/5 "2022-03-24T08:50:47Z")

</div>

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