Search in sources :

Example 1 with FieldCapabilitiesResponse

use of org.opensearch.action.fieldcaps.FieldCapabilitiesResponse in project OpenSearch by opensearch-project.

the class SearchIT method testFieldCapsWithNonExistentFields.

public void testFieldCapsWithNonExistentFields() throws IOException {
    FieldCapabilitiesRequest request = new FieldCapabilitiesRequest().indices("index2").fields("nonexistent");
    FieldCapabilitiesResponse response = execute(request, highLevelClient()::fieldCaps, highLevelClient()::fieldCapsAsync);
    assertTrue(response.get().isEmpty());
}
Also used : FieldCapabilitiesResponse(org.opensearch.action.fieldcaps.FieldCapabilitiesResponse) FieldCapabilitiesRequest(org.opensearch.action.fieldcaps.FieldCapabilitiesRequest)

Example 2 with FieldCapabilitiesResponse

use of org.opensearch.action.fieldcaps.FieldCapabilitiesResponse in project OpenSearch by opensearch-project.

the class SearchDocumentationIT method testFieldCaps.

public void testFieldCaps() throws Exception {
    indexSearchTestData();
    RestHighLevelClient client = highLevelClient();
    // tag::field-caps-request
    FieldCapabilitiesRequest request = new FieldCapabilitiesRequest().fields("user").indices("posts", "authors", "contributors");
    // end::field-caps-request
    // tag::field-caps-request-indicesOptions
    // <1>
    request.indicesOptions(IndicesOptions.lenientExpandOpen());
    // end::field-caps-request-indicesOptions
    // tag::field-caps-execute
    FieldCapabilitiesResponse response = client.fieldCaps(request, RequestOptions.DEFAULT);
    // end::field-caps-execute
    // tag::field-caps-response
    // <1>
    Map<String, FieldCapabilities> userResponse = response.getField("user");
    FieldCapabilities textCapabilities = userResponse.get("keyword");
    boolean isSearchable = textCapabilities.isSearchable();
    boolean isAggregatable = textCapabilities.isAggregatable();
    // <2>
    String[] indices = textCapabilities.indices();
    // <3>
    String[] nonSearchableIndices = textCapabilities.nonSearchableIndices();
    // <4>
    String[] nonAggregatableIndices = textCapabilities.nonAggregatableIndices();
    // end::field-caps-response
    assertThat(userResponse.keySet(), containsInAnyOrder("keyword", "text"));
    assertTrue(isSearchable);
    assertFalse(isAggregatable);
    assertArrayEquals(indices, new String[] { "authors", "contributors" });
    assertNull(nonSearchableIndices);
    assertArrayEquals(nonAggregatableIndices, new String[] { "authors" });
    // tag::field-caps-execute-listener
    ActionListener<FieldCapabilitiesResponse> listener = new ActionListener<FieldCapabilitiesResponse>() {

        @Override
        public void onResponse(FieldCapabilitiesResponse response) {
        // <1>
        }

        @Override
        public void onFailure(Exception e) {
        // <2>
        }
    };
    // end::field-caps-execute-listener
    // Replace the empty listener by a blocking listener for tests.
    CountDownLatch latch = new CountDownLatch(1);
    listener = new LatchedActionListener<>(listener, latch);
    // tag::field-caps-execute-async
    // <1>
    client.fieldCapsAsync(request, RequestOptions.DEFAULT, listener);
    // end::field-caps-execute-async
    assertTrue(latch.await(30L, TimeUnit.SECONDS));
}
Also used : FieldCapabilities(org.opensearch.action.fieldcaps.FieldCapabilities) RestHighLevelClient(org.opensearch.client.RestHighLevelClient) Matchers.containsString(org.hamcrest.Matchers.containsString) CountDownLatch(java.util.concurrent.CountDownLatch) IOException(java.io.IOException) LatchedActionListener(org.opensearch.action.LatchedActionListener) ActionListener(org.opensearch.action.ActionListener) FieldCapabilitiesResponse(org.opensearch.action.fieldcaps.FieldCapabilitiesResponse) FieldCapabilitiesRequest(org.opensearch.action.fieldcaps.FieldCapabilitiesRequest)

Example 3 with FieldCapabilitiesResponse

use of org.opensearch.action.fieldcaps.FieldCapabilitiesResponse in project OpenSearch by opensearch-project.

the class FieldCapabilitiesIT method testFieldAliasWithWildcard.

public void testFieldAliasWithWildcard() {
    FieldCapabilitiesResponse response = client().prepareFieldCaps().setFields("route*").get();
    assertIndices(response, "old_index", "new_index");
    assertEquals(1, response.get().size());
    assertTrue(response.get().containsKey("route_length_miles"));
}
Also used : FieldCapabilitiesResponse(org.opensearch.action.fieldcaps.FieldCapabilitiesResponse)

Example 4 with FieldCapabilitiesResponse

use of org.opensearch.action.fieldcaps.FieldCapabilitiesResponse in project OpenSearch by opensearch-project.

the class FieldCapabilitiesIT method testWithIndexAlias.

public void testWithIndexAlias() {
    FieldCapabilitiesResponse response = client().prepareFieldCaps("current").setFields("*").get();
    assertIndices(response, "new_index");
    FieldCapabilitiesResponse response1 = client().prepareFieldCaps("current", "old_index").setFields("*").get();
    assertIndices(response1, "old_index", "new_index");
    FieldCapabilitiesResponse response2 = client().prepareFieldCaps("current", "old_index", "new_index").setFields("*").get();
    assertEquals(response1, response2);
}
Also used : FieldCapabilitiesResponse(org.opensearch.action.fieldcaps.FieldCapabilitiesResponse)

Example 5 with FieldCapabilitiesResponse

use of org.opensearch.action.fieldcaps.FieldCapabilitiesResponse in project OpenSearch by opensearch-project.

the class FieldCapabilitiesIT method testFieldAliasFiltering.

public void testFieldAliasFiltering() {
    FieldCapabilitiesResponse response = client().prepareFieldCaps().setFields("secret-soundtrack", "route_length_miles").get();
    assertIndices(response, "old_index", "new_index");
    assertEquals(1, response.get().size());
    assertTrue(response.get().containsKey("route_length_miles"));
}
Also used : FieldCapabilitiesResponse(org.opensearch.action.fieldcaps.FieldCapabilitiesResponse)

Aggregations

FieldCapabilitiesResponse (org.opensearch.action.fieldcaps.FieldCapabilitiesResponse)11 FieldCapabilities (org.opensearch.action.fieldcaps.FieldCapabilities)5 FieldCapabilitiesRequest (org.opensearch.action.fieldcaps.FieldCapabilitiesRequest)4 ArrayList (java.util.ArrayList)2 Matchers.containsString (org.hamcrest.Matchers.containsString)2 IOException (java.io.IOException)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 ActionListener (org.opensearch.action.ActionListener)1 LatchedActionListener (org.opensearch.action.LatchedActionListener)1 GetMappingsResponse (org.opensearch.action.admin.indices.mapping.get.GetMappingsResponse)1 IndexRequestBuilder (org.opensearch.action.index.IndexRequestBuilder)1 RestHighLevelClient (org.opensearch.client.RestHighLevelClient)1 MappingMetadata (org.opensearch.cluster.metadata.MappingMetadata)1