Make a custom parameter source send two (related) queries

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

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 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.

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

{
  "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?

2 Likes

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...

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