Package: esqa
Table of ContentsOverviewInstallBehaviorFunctionsOverviewEsqaautomates the checks the qualities of the Elasticsearch indices
as the unit test frameworks such as RSpec or PyTests. Users add the test cases
into the setting files and checks if the target indices is build as expected running the commandesqa.Install$pipinstallesqaBehaviorWhen we run Esqa, the following steps are executed.Submit Es query to an Elasticsearch clusterGet the result ranking from ElasticsearchCheck if the rankings from Es cluster satisfy the conditions described in configuration fileThe following is the image.FunctionsSpecifically esqa provides two functions,assertionandcompute distancebetween rankings from two index and query settings.With assertion function, we can check if the results ranking satisfy the expectation for the specified queries.
With distance function, we can see the queries which is much different from previous settings (index and query`).The successive sections, we see the assertion and distance functions.Assertion functionEsqa provides theesqacommand which check if the queries gets the expected search rankings from Elasticsearch indices.We run theesqacommand specifying the configuration file and target index.$esqaassertion--configsample_config.json--indexdocument-indexConfigurationsEsqa has the settings file in which we add the test cases. The following is an example of the setting file of esqa.
The setting file means that results from Elasticsearch clusters must satisfy the conditions defined inassertsblock when we run the defined query (searchingengineerto themessagefield) to the target index.{"cases":[{"name":"match query","request":{"query":{"match":{"message":{"query":"engineer"}}}},"asserts":[{"type":"equal","rank":0,"item":{"field":"document_id","value":"24343"}}]}]}We add all the test cases intocasesblock.
Each test cases have three elementsname,requestandasserts.nameis the name of the test case.requestis the target Es query which we want to validate.
We add a set of expected behaviors to theassertsblock.Theassertsblock contains the conditions that search results from
Elasticsearch cluster must satisfy. Each condition
contains several elementstype,rankanditem.ElementSummarytypecondition types (equal、higher、lower）rankrank of the specified itemitemitem stored in Elasticsearch indices specified in rank element must satisfyitemelement specifies the document in Es indices. The item is specified with the field value.ElementSummaryfieldfield namevaluevalue of the field specified infieldelementTemplatesSometimes queries in the test cases are almost the same.
In such cases, esqa providestemplatesin the configuration files.Template files are JSON file which contains an Elasticsearch query
withvariables.The following is an example of template file. As we can see,queryblock contains a variable${query_str}. The variables are injected
from the Esqa configuration file.{"query":{"match":{"message":{"query":"${query_str}"}}}}The following is a configuration file which specifies the template file.
To uses template files in the configuration file, we addtemplateelement inqueryblock.
The variables in the specified template file need to be added in thequeryblock.
For example the configuration file added a variablequery_strdefined in template file.{"templates":[{"name":"basic_query","path":"tests/fixtures/default_template.json"}],"cases":[{"name":"match identical","request":{"template":"basic_query","query_str":"engineer"},"asserts":[{"type":"equal","rank":0,"item":{"field":"id","value":"2324"}}]}]}Distance functionWhen we tune the Es indices, we somtimes want to compare the rankings from the previous indices.
Esqa computes the comparison between the rankings in the current settings and previous ones.Before we run the command we prepare the configuration for the esqa distance function.
The format is the almost the same as validation settings except that the settings for
distance function does not have assert blocks.{"templates":[{"name":"basic_query","path":"sample/template.json"}],"cases":[{"request":{"template":"basic_query","query_str":"Windows PC"},"name":"Windows PC"},{"request":{"template":"basic_query","query_str":"Tablet"},"name":"Tablet"}]}Before changing the Es settings, we run the save command to preserve the current ranking.esqasave--configsample/ranking.json--indexsample>output/ranking_before_change.jsonThen we change the Es index or query settings and run distance command specifying the ranking file.esqadistance--configsample/compared_ranking.json--indexsample--rankingoutput/ranking.json[{"name":"Windows PC","similarity":0.5,"ranking_pair":[["4","6"],["5","4"],["6","5"]]},{"name":"Tablet","similarity":0.5416666666666666,"ranking_pair":[["22","21"],["23","22"],["3","23"],["21","3"]]}]Or, we can compare between two preserved rankings by distance-rankings command.esqadistance-rankings--ranking1output/ranking1.json--ranking2output/ranking2.json[{"name":"Windows PC","similarity":0.5,"ranking_pair":[["4","6"],["5","4"],["6","5"]]},{"name":"Tablet","similarity":0.5416666666666666,"ranking_pair":[["22","21"],["23","22"],["3","23"],["21","3"]]}]Finally, we get the query cases that have been changed significantly.