put-query-ruleset.asciidoc 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. [role="xpack"]
  2. [[put-query-ruleset]]
  3. === Create or update query ruleset
  4. preview::[]
  5. ++++
  6. <titleabbrev>Create or update query ruleset</titleabbrev>
  7. ++++
  8. Creates or updates a query ruleset.
  9. [[put-query-ruleset-request]]
  10. ==== {api-request-title}
  11. `PUT _query_rules/<ruleset_id>`
  12. [[put-query-ruleset-prereqs]]
  13. ==== {api-prereq-title}
  14. Requires the `manage_cluster` privilege.
  15. [[put-query-ruleset-path-params]]
  16. ==== {api-path-parms-title}
  17. `<body>`::
  18. (Required, object)
  19. Contains parameters for a query ruleset:
  20. ====
  21. `rules`::
  22. (Required, array of objects)
  23. The specific rules included in this query ruleset.
  24. Each rule must have the following information:
  25. - `rule_id` (Required, string)
  26. A unique identifier for this rule.
  27. - `type` (Required, string)
  28. The type of rule. At this time only `pinned` query rule types are allowed.
  29. - `criteria` (Required, array of objects)
  30. - `actions` (Required, object)
  31. The actions to take when the rule is matched. The format of this action depends on the rule type.
  32. Criteria must have the following information:
  33. - `type` (Required, string)
  34. The type of criteria. At this time only `exact` criteria types are allowed.
  35. - `metadata` (Required, string)
  36. The metadata field to match against. At this time only `query_string` metadata types are allowed.
  37. - `value` (Required, string)
  38. The value to match against the metadata field.
  39. Actions depend on the rule type.
  40. For `pinned` rules, actions follow the format specified by the <<query-dsl-pinned-query,Pinned Query>>.
  41. The following actions are allowed:
  42. - `ids` (Optional, array of strings)
  43. The The unique <<mapping-id-field, document IDs>> of the documents to pin. Only one of `ids` or `docs` may be specified, and at least one must be specified.
  44. - `docs` (Optional, array of objects)
  45. The documents to pin. Only one of `ids` or `docs` may be specified, and at least one must be specified.
  46. You can specify the following attributes for each document:
  47. +
  48. --
  49. - `_index` (Required, string)
  50. The index of the document to pin.
  51. - `_id` (Required, string)
  52. The unique <<mapping-id-field, document ID>>.
  53. --
  54. ====
  55. [[put-query-ruleset-example]]
  56. ==== {api-examples-title}
  57. The following example creates a new query ruleset called `my-ruleset`.
  58. Two rules are associated with `my-ruleset`:
  59. - `my-rule1` will pin documents with IDs `id1` and `id2` when the `query_string` exactly matches `marvel`.
  60. - `my-rule2` will pin documents from different, specified indices with IDs `id3` and `id4` when the `query_string` exactly matches `dc`.
  61. [source,console]
  62. ----
  63. PUT _query_rules/my-ruleset
  64. {
  65. "rules": [
  66. {
  67. "rule_id": "my-rule1",
  68. "type": "pinned",
  69. "criteria": [
  70. {
  71. "type": "exact",
  72. "metadata": "query_string",
  73. "value": "marvel"
  74. }
  75. ],
  76. "actions": {
  77. "ids": [
  78. "id1",
  79. "id2"
  80. ]
  81. }
  82. },
  83. {
  84. "rule_id": "my-rule2",
  85. "type": "pinned",
  86. "criteria": [
  87. {
  88. "type": "exact",
  89. "metadata": "query_string",
  90. "value": "dc"
  91. }
  92. ],
  93. "actions": {
  94. "docs": [
  95. {
  96. "_index": "index1",
  97. "_id": "id3"
  98. },
  99. {
  100. "_index": "index2",
  101. "_id": "id4"
  102. }
  103. ]
  104. }
  105. }
  106. ]
  107. }
  108. ----
  109. // TESTSETUP
  110. //////////////////////////
  111. [source,console]
  112. --------------------------------------------------
  113. DELETE _query_rules/my-ruleset
  114. --------------------------------------------------
  115. // TEARDOWN
  116. //////////////////////////