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());
}
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));
}
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"));
}
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);
}
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"));
}
Aggregations