Search in sources :

Example 6 with FieldCapabilitiesResponse

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

the class FieldCapabilitiesIT method testFieldAliasFilteringWithWildcard.

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

Example 7 with FieldCapabilitiesResponse

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

the class FieldCapabilitiesIT method testFieldAlias.

public void testFieldAlias() {
    FieldCapabilitiesResponse response = client().prepareFieldCaps().setFields("distance", "route_length_miles").get();
    assertIndices(response, "old_index", "new_index");
    // Ensure the response has entries for both requested fields.
    assertTrue(response.get().containsKey("distance"));
    assertTrue(response.get().containsKey("route_length_miles"));
    // Check the capabilities for the 'distance' field.
    Map<String, FieldCapabilities> distance = response.getField("distance");
    assertEquals(2, distance.size());
    assertTrue(distance.containsKey("double"));
    assertEquals(new FieldCapabilities("distance", "double", true, true, new String[] { "old_index" }, null, null, Collections.emptyMap()), distance.get("double"));
    assertTrue(distance.containsKey("text"));
    assertEquals(new FieldCapabilities("distance", "text", true, false, new String[] { "new_index" }, null, null, Collections.emptyMap()), distance.get("text"));
    // Check the capabilities for the 'route_length_miles' alias.
    Map<String, FieldCapabilities> routeLength = response.getField("route_length_miles");
    assertEquals(1, routeLength.size());
    assertTrue(routeLength.containsKey("double"));
    assertEquals(new FieldCapabilities("route_length_miles", "double", true, true, null, null, null, Collections.emptyMap()), routeLength.get("double"));
}
Also used : FieldCapabilities(org.opensearch.action.fieldcaps.FieldCapabilities) FieldCapabilitiesResponse(org.opensearch.action.fieldcaps.FieldCapabilitiesResponse)

Example 8 with FieldCapabilitiesResponse

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

the class FieldFilterMapperPluginTests method testFieldCapabilities.

public void testFieldCapabilities() {
    List<String> allFields = new ArrayList<>(ALL_FLAT_FIELDS);
    allFields.addAll(ALL_OBJECT_FIELDS);
    FieldCapabilitiesResponse index1 = client().fieldCaps(new FieldCapabilitiesRequest().fields("*").indices("index1")).actionGet();
    assertFieldCaps(index1, allFields);
    FieldCapabilitiesResponse filtered = client().fieldCaps(new FieldCapabilitiesRequest().fields("*").indices("filtered")).actionGet();
    List<String> filteredFields = new ArrayList<>(FILTERED_FLAT_FIELDS);
    filteredFields.addAll(ALL_OBJECT_FIELDS);
    assertFieldCaps(filtered, filteredFields);
    // double check that submitting the filtered mappings to an unfiltered index leads to the same field_caps output
    // as the one coming from a filtered index with same mappings
    GetMappingsResponse getMappingsResponse = client().admin().indices().prepareGetMappings("filtered").get();
    MappingMetadata filteredMapping = getMappingsResponse.getMappings().get("filtered");
    assertAcked(client().admin().indices().prepareCreate("test").addMapping("_doc", filteredMapping.getSourceAsMap()));
    FieldCapabilitiesResponse test = client().fieldCaps(new FieldCapabilitiesRequest().fields("*").indices("test")).actionGet();
    // properties.value is an object field in the new mapping
    filteredFields.add("properties.value");
    assertFieldCaps(test, filteredFields);
}
Also used : ArrayList(java.util.ArrayList) FieldCapabilitiesResponse(org.opensearch.action.fieldcaps.FieldCapabilitiesResponse) FieldCapabilitiesRequest(org.opensearch.action.fieldcaps.FieldCapabilitiesRequest) MappingMetadata(org.opensearch.cluster.metadata.MappingMetadata) GetMappingsResponse(org.opensearch.action.admin.indices.mapping.get.GetMappingsResponse)

Example 9 with FieldCapabilitiesResponse

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

the class SearchIT method testFieldCaps.

public void testFieldCaps() throws IOException {
    FieldCapabilitiesRequest request = new FieldCapabilitiesRequest().indices("index1", "index2").fields("rating", "field");
    FieldCapabilitiesResponse response = execute(request, highLevelClient()::fieldCaps, highLevelClient()::fieldCapsAsync);
    assertThat(response.getIndices(), arrayContaining("index1", "index2"));
    // Check the capabilities for the 'rating' field.
    assertTrue(response.get().containsKey("rating"));
    Map<String, FieldCapabilities> ratingResponse = response.getField("rating");
    assertEquals(2, ratingResponse.size());
    FieldCapabilities expectedKeywordCapabilities = new FieldCapabilities("rating", "keyword", true, true, new String[] { "index2" }, null, null, Collections.emptyMap());
    assertEquals(expectedKeywordCapabilities, ratingResponse.get("keyword"));
    FieldCapabilities expectedLongCapabilities = new FieldCapabilities("rating", "long", true, true, new String[] { "index1" }, null, null, Collections.emptyMap());
    assertEquals(expectedLongCapabilities, ratingResponse.get("long"));
    // Check the capabilities for the 'field' field.
    assertTrue(response.get().containsKey("field"));
    Map<String, FieldCapabilities> fieldResponse = response.getField("field");
    assertEquals(1, fieldResponse.size());
    FieldCapabilities expectedTextCapabilities = new FieldCapabilities("field", "text", true, false, null, null, null, Collections.emptyMap());
    assertEquals(expectedTextCapabilities, fieldResponse.get("text"));
}
Also used : FieldCapabilities(org.opensearch.action.fieldcaps.FieldCapabilities) FieldCapabilitiesResponse(org.opensearch.action.fieldcaps.FieldCapabilitiesResponse) FieldCapabilitiesRequest(org.opensearch.action.fieldcaps.FieldCapabilitiesRequest) Matchers.containsString(org.hamcrest.Matchers.containsString)

Example 10 with FieldCapabilitiesResponse

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

the class FieldCapabilitiesIT method testWithIndexFilter.

public void testWithIndexFilter() throws InterruptedException {
    assertAcked(prepareCreate("index-1").addMapping("_doc", "timestamp", "type=date", "field1", "type=keyword"));
    assertAcked(prepareCreate("index-2").addMapping("_doc", "timestamp", "type=date", "field1", "type=long"));
    List<IndexRequestBuilder> reqs = new ArrayList<>();
    reqs.add(client().prepareIndex("index-1").setSource("timestamp", "2015-07-08"));
    reqs.add(client().prepareIndex("index-1").setSource("timestamp", "2018-07-08"));
    reqs.add(client().prepareIndex("index-2").setSource("timestamp", "2019-10-12"));
    reqs.add(client().prepareIndex("index-2").setSource("timestamp", "2020-07-08"));
    indexRandom(true, reqs);
    FieldCapabilitiesResponse response = client().prepareFieldCaps("index-*").setFields("*").get();
    assertIndices(response, "index-1", "index-2");
    Map<String, FieldCapabilities> newField = response.getField("field1");
    assertEquals(2, newField.size());
    assertTrue(newField.containsKey("long"));
    assertTrue(newField.containsKey("keyword"));
    response = client().prepareFieldCaps("index-*").setFields("*").setIndexFilter(QueryBuilders.rangeQuery("timestamp").gte("2019-11-01")).get();
    assertIndices(response, "index-2");
    newField = response.getField("field1");
    assertEquals(1, newField.size());
    assertTrue(newField.containsKey("long"));
    response = client().prepareFieldCaps("index-*").setFields("*").setIndexFilter(QueryBuilders.rangeQuery("timestamp").lte("2017-01-01")).get();
    assertIndices(response, "index-1");
    newField = response.getField("field1");
    assertEquals(1, newField.size());
    assertTrue(newField.containsKey("keyword"));
}
Also used : IndexRequestBuilder(org.opensearch.action.index.IndexRequestBuilder) FieldCapabilities(org.opensearch.action.fieldcaps.FieldCapabilities) ArrayList(java.util.ArrayList) 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