test-query-ruleset.asciidoc 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. [role="xpack"]
  2. [[test-query-ruleset]]
  3. === Test query ruleset
  4. ++++
  5. <titleabbrev>Tests query ruleset</titleabbrev>
  6. ++++
  7. Evaluates match criteria against a query ruleset to identify the rules that would match that criteria.
  8. preview::[]
  9. [[test-query-ruleset-request]]
  10. ==== {api-request-title}
  11. `POST _query_rules/<ruleset_id>/_test`
  12. [[test-query-ruleset-prereq]]
  13. ==== {api-prereq-title}
  14. Requires the `manage_search_query_rules` privilege.
  15. [[test-query-ruleset-path-params]]
  16. ==== {api-path-parms-title}
  17. `<ruleset_id>`::
  18. (Required, string)
  19. [[test-query-rule-request-body]]
  20. ==== {api-request-body-title}
  21. `match_criteria`::
  22. (Required, object) Defines the match criteria to apply to rules in the given query ruleset.
  23. Match criteria should match the keys defined in the `criteria.metadata` field of the rule.
  24. [[test-query-ruleset-response-codes]]
  25. ==== {api-response-codes-title}
  26. `400`::
  27. The `ruleset_id` or `match_criteria` were not provided.
  28. `404` (Missing resources)::
  29. No query ruleset matching `ruleset_id` could be found.
  30. [[test-query-ruleset-example]]
  31. ==== {api-examples-title}
  32. To test a ruleset, provide the match criteria that you want to test against:
  33. ////
  34. [source,console]
  35. --------------------------------------------------
  36. PUT _query_rules/my-ruleset
  37. {
  38. "rules": [
  39. {
  40. "rule_id": "my-rule1",
  41. "type": "pinned",
  42. "criteria": [
  43. {
  44. "type": "contains",
  45. "metadata": "query_string",
  46. "values": [ "pugs", "puggles" ]
  47. }
  48. ],
  49. "actions": {
  50. "ids": [
  51. "id1",
  52. "id2"
  53. ]
  54. }
  55. },
  56. {
  57. "rule_id": "my-rule2",
  58. "type": "pinned",
  59. "criteria": [
  60. {
  61. "type": "fuzzy",
  62. "metadata": "query_string",
  63. "values": [ "rescue dogs" ]
  64. }
  65. ],
  66. "actions": {
  67. "docs": [
  68. {
  69. "_index": "index1",
  70. "_id": "id3"
  71. },
  72. {
  73. "_index": "index2",
  74. "_id": "id4"
  75. }
  76. ]
  77. }
  78. }
  79. ]
  80. }
  81. --------------------------------------------------
  82. // TESTSETUP
  83. [source,console]
  84. --------------------------------------------------
  85. DELETE _query_rules/my-ruleset
  86. --------------------------------------------------
  87. // TEARDOWN
  88. ////
  89. [source,console]
  90. ----
  91. POST _query_rules/my-ruleset/_test
  92. {
  93. "match_criteria": {
  94. "query_string": "puggles"
  95. }
  96. }
  97. ----
  98. A sample response:
  99. [source,console-result]
  100. ----
  101. {
  102. "total_matched_rules": 1,
  103. "matched_rules": [
  104. {
  105. "ruleset_id": "my-ruleset",
  106. "rule_id": "my-rule1"
  107. }
  108. ]
  109. }
  110. ----