# Make a custom parameter source send two (related) queries

**URL:** <https://discuss.elastic.co/t/make-a-custom-parameter-source-send-two-related-queries/303403>\
**Category:** Elasticsearch\
**Tags:** rally\
**Created:** [April 27, 2022, 12:52pm UTC](https://discuss.elastic.co/t/make-a-custom-parameter-source-send-two-related-queries/303403 "2022-04-27T12:52:35Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![jmlucjav](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jmlucjav/32/5870_2.png) [@jmlucjav](https://discuss.elastic.co/u/jmlucjav)\
**Post date:** [April 27, 2022, 12:52pm UTC](https://discuss.elastic.co/t/make-a-custom-parameter-source-send-two-related-queries/303403/1 "2022-04-27T12:52:35Z")

</div>

Hi,

when benchmarking with rally, in order to make it realistic, I want to issue two ES queries (they are related so they need to be created in context) whenever my custom source is invoked.

Is there a good way to do this?

thanks

---

<div class="post-metadata">

**Author:** ![RickBoyd](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rickboyd/32/80022_2.png) [@RickBoyd](https://discuss.elastic.co/u/RickBoyd)\
**Post date:** [April 27, 2022, 2:17pm UTC](https://discuss.elastic.co/t/make-a-custom-parameter-source-send-two-related-queries/303403/2 "2022-04-27T14:17:16Z")

</div>

Hi! what a neat question, thank you for using Rally, and going deep on the functionality.

To accomplish what you are looking for, you can use a [composite](https://esrally.readthedocs.io/en/stable/track.html#composite) operation, and instead of prescribing a `requests` parameter in the task, you would return it in the parameters from the parameter source's `params` call.

```auto
class FoodParamSource:
  def __init__ (self, track, params, **kwargs):
    self.params = params

  def params(self):
    search_term = randomfood.generate() # 'hot dog' | 'hamburger' | 'spaghetti'
    return {
      **self.params,
      "requests": [
          {
            "stream": [
              {
                "operation-type": "search",
                "body": {
                  "query": {
                    "bool": {
                      "must": {
                        "query_string": {
                          "query": search_term
                        }
                      }
                    }
                  }
                }
              },
              {
                "operation-type": "search",
                "body": {
                  "query": {
                    "bool": {
                      "must_not": {
                        "query_string": {
                          "query": search_term
                        }
                      }
                    }
                  }
                }
              }
            ]
          }
        ]
    }

```

then one would simply have

```auto
{
  "operation": {
    "operation-type": "composite",
    "param-source": "food-param-source"
  }
}

```

in their track, provided they registered the class as `food-param-source`.

... the above code is not tested or anything but hopefully illustrates the generation flow for you.

Does that help?

---

<div class="post-metadata">

**Author:** ![jmlucjav](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jmlucjav/32/5870_2.png) [@jmlucjav](https://discuss.elastic.co/u/jmlucjav)\
**Post date:** [April 28, 2022, 1:00pm UTC](https://discuss.elastic.co/t/make-a-custom-parameter-source-send-two-related-queries/303403/3 "2022-04-28T13:00:29Z")

</div>

It absolutely does help. Will try it out. Much appreciated. I have another rally q, but will open a new thread to keep things clean and tidy...

---

<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 26, 2022, 1:01pm UTC](https://discuss.elastic.co/t/make-a-custom-parameter-source-send-two-related-queries/303403/4 "2022-05-26T13:01:12Z")

</div>

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