diff --git a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/transport/action/getpolicy/TransportGetPoliciesAction.kt b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/transport/action/getpolicy/TransportGetPoliciesAction.kt index 10c0f7c10..1fa0f1130 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/transport/action/getpolicy/TransportGetPoliciesAction.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/transport/action/getpolicy/TransportGetPoliciesAction.kt @@ -81,7 +81,7 @@ class TransportGetPoliciesAction @Inject constructor( QueryBuilders .queryStringQuery(params.queryString) .defaultOperator(Operator.AND) - .field("policy.policy_id") + .field("policy.policy_id.keyword") ) val searchSourceBuilder = SearchSourceBuilder() diff --git a/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/resthandler/IndexStateManagementRestApiIT.kt b/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/resthandler/IndexStateManagementRestApiIT.kt index 435961b9b..30c1c3263 100644 --- a/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/resthandler/IndexStateManagementRestApiIT.kt +++ b/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/resthandler/IndexStateManagementRestApiIT.kt @@ -316,4 +316,42 @@ class IndexStateManagementRestApiIT : IndexStateManagementRestTestCase() { assertEquals(expectedMessage.toString(), actualMessage.toString()) } + + fun `test get policies with hyphen`() { + val randomPolicy = randomPolicy(id = "testing-hyphens-01") + createPolicy(randomPolicy, policyId = randomPolicy.id, refresh = true) + val policy = getPolicy(randomPolicy.id) + + val response = client().makeRequest(RestRequest.Method.GET.toString(), "$POLICY_BASE_URI?queryString=*testing-hyphens*") + + val actualMessage = response.asMap() + val expectedMessage = mapOf( + "total_policies" to 1, + "policies" to listOf( + mapOf( + _SEQ_NO to policy.seqNo, + _ID to policy.id, + _PRIMARY_TERM to policy.primaryTerm, + Policy.POLICY_TYPE to mapOf( + "schema_version" to policy.schemaVersion, + "policy_id" to policy.id, + "last_updated_time" to policy.lastUpdatedTime.toEpochMilli(), + "default_state" to policy.defaultState, + "ism_template" to null, + "description" to policy.description, + "error_notification" to policy.errorNotification, + "states" to policy.states.map { + mapOf( + "name" to it.name, + "transitions" to it.transitions, + "actions" to it.actions + ) + } + ) + ) + ) + ) + + assertEquals(expectedMessage.toString(), actualMessage.toString()) + } }