org.elasticsearch.action.admin.indices.mapping.get.GetFieldMappingsRequest Java Examples

The following examples show how to use org.elasticsearch.action.admin.indices.mapping.get.GetFieldMappingsRequest. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: QueryDescParser.java    From elasticsearch-sql with MIT License 6 votes vote down vote up
@Override
public void parse(ElasticDslContext dslContext) {
    if(dslContext.getSqlContext().descOperation()!=null){
        dslContext.getParseResult().setSqlOperation(SqlOperation.DESC);
        GetFieldMappingsRequest getFieldMappingsRequest = new GetFieldMappingsRequest();
        GetMappingsRequest getMappingsRequest = new GetMappingsRequest();
        ElasticsearchParser.TableRefContext tableRefContext=dslContext.getSqlContext().descOperation().tableRef();
        String index = tableRefContext.indexName.getText();
        if(dslContext.getSqlContext().descOperation().identity()!=null){
            String field = dslContext.getSqlContext().descOperation().identity().getText();
            getFieldMappingsRequest.indices(index);
            getFieldMappingsRequest.fields(field);
            dslContext.getParseResult().setFieldMappingsRequest(getFieldMappingsRequest);
        }else{
            getMappingsRequest.indices(index);
            dslContext.getParseResult().setMappingsRequest(getMappingsRequest);
        }

    }
}
 
Example #2
Source File: RestGetFieldMappingAction.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
@Override
public void handleRequest(final RestRequest request, final RestChannel channel, final Client client) {
    final String[] indices = Strings.splitStringByCommaToArray(request.param("index"));
    final String[] types = request.paramAsStringArrayOrEmptyIfAll("type");
    final String[] fields = Strings.splitStringByCommaToArray(request.param("fields"));
    GetFieldMappingsRequest getMappingsRequest = new GetFieldMappingsRequest();
    getMappingsRequest.indices(indices).types(types).fields(fields).includeDefaults(request.paramAsBoolean("include_defaults", false));
    getMappingsRequest.indicesOptions(IndicesOptions.fromRequest(request, getMappingsRequest.indicesOptions()));
    getMappingsRequest.local(request.paramAsBoolean("local", getMappingsRequest.local()));
    client.admin().indices().getFieldMappings(getMappingsRequest, new RestBuilderListener<GetFieldMappingsResponse>(channel) {

        @SuppressWarnings("unchecked")
        @Override
        public RestResponse buildResponse(GetFieldMappingsResponse response, XContentBuilder builder) throws Exception {
            ImmutableMap<String, ImmutableMap<String, ImmutableMap<String, FieldMappingMetaData>>> mappingsByIndex = response.mappings();

            boolean isPossibleSingleFieldRequest = indices.length == 1 && types.length == 1 && fields.length == 1;
            if (isPossibleSingleFieldRequest && isFieldMappingMissingField(mappingsByIndex)) {
                return new BytesRestResponse(OK, builder.startObject().endObject());
            }

            RestStatus status = OK;
            if (mappingsByIndex.isEmpty() && fields.length > 0) {
                status = NOT_FOUND;
            }
            builder.startObject();
            response.toXContent(builder, request);
            builder.endObject();
            return new BytesRestResponse(status, builder);
        }
    });
}
 
Example #3
Source File: ElasticsearchQueryStoreTest.java    From foxtrot with Apache License 2.0 5 votes vote down vote up
@Test
public void testSaveBulkLargeTextNodeWithBlockingEnabled() throws Exception {
    when(removerConfiguration.getBlockPercentage()).thenReturn(100);
    Table table = tableMetadataManager.get(TestUtils.TEST_TABLE_NAME);

    Document originalDocument = createLargeDummyDocument();
    Document translatedDocument = TestUtils.translatedDocumentWithRowKeyVersion1(table, originalDocument);
    doReturn(translatedDocument).when(dataStore)
            .save(table, originalDocument);
    queryStore.save(TestUtils.TEST_TABLE_NAME, originalDocument);
    val currentIndex = ElasticsearchUtils.getCurrentIndex(TestUtils.TEST_TABLE_NAME, originalDocument.getTimestamp());
    val response = elasticsearchConnection.getClient()
            .prepareGet(currentIndex, ElasticsearchUtils.DOCUMENT_TYPE_NAME, originalDocument.getId())
            .setStoredFields(ElasticsearchUtils.DOCUMENT_META_TIMESTAMP_FIELD_NAME, "testField", "testLargeField")
            .execute()
            .actionGet();
    assertTrue(response.isExists());
    val request = new GetFieldMappingsRequest();
    request.indices(currentIndex);
    request.fields("*");

    val mappings = elasticsearchConnection.getClient()
            .admin()
            .indices()
            .getFieldMappings(request)
            .get();

    Set<String> expectedFields = Sets.newHashSet("_index", "date.minuteOfHour", "date.year",
            "date.dayOfMonth", "testField", "testField.analyzed",
            "_all", "date.dayOfWeek", "date.minuteOfDay",
            "_parent", "date.monthOfYear", "__FOXTROT_METADATA__.time",
            "time.date", "_version", "date.weekOfYear",
            "_routing", "__FOXTROT_METADATA__.rawStorageId",
            "_type", "__FOXTROT_METADATA__.id", "date.hourOfDay",
            "_seq_no", "_field_names", "_source", "_id", "time", "_uid");
    assertTrue(ObjectUtils.equals(expectedFields, mappings.mappings().get(currentIndex).get(ElasticsearchUtils.DOCUMENT_TYPE_NAME).keySet()));
}
 
Example #4
Source File: ElasticsearchQueryStoreTest.java    From foxtrot with Apache License 2.0 5 votes vote down vote up
@Test
public void testSaveBulkLargeTextNodeWithBlockingDisabled() throws Exception {
    when(removerConfiguration.getBlockPercentage()).thenReturn(0);

    Table table = tableMetadataManager.get(TestUtils.TEST_TABLE_NAME);

    Document originalDocument = createLargeDummyDocument();
    Document translatedDocument = TestUtils.translatedDocumentWithRowKeyVersion1(table, originalDocument);
    doReturn(translatedDocument).when(dataStore)
            .save(table, originalDocument);
    queryStore.save(TestUtils.TEST_TABLE_NAME, originalDocument);
    val currentIndex = ElasticsearchUtils.getCurrentIndex(TestUtils.TEST_TABLE_NAME, originalDocument.getTimestamp());
    val response = elasticsearchConnection.getClient()
            .prepareGet(currentIndex, ElasticsearchUtils.DOCUMENT_TYPE_NAME, originalDocument.getId())
            .setStoredFields(ElasticsearchUtils.DOCUMENT_META_TIMESTAMP_FIELD_NAME, "testField", "testLargeField")
            .execute()
            .actionGet();
    assertTrue(response.isExists());
    val request = new GetFieldMappingsRequest();
    request.indices(currentIndex);
    request.fields("*");

    val mappings = elasticsearchConnection.getClient()
            .admin()
            .indices()
            .getFieldMappings(request)
            .get();

    Set<String> expectedFields = Sets.newHashSet("_index", "date.minuteOfHour", "date.year",
            "date.dayOfMonth", "testField", "testField.analyzed",
            "testLargeField",
            "testLargeField.analyzed",
            "_all", "date.dayOfWeek", "date.minuteOfDay",
            "_parent", "date.monthOfYear", "__FOXTROT_METADATA__.time",
            "time.date", "_version", "date.weekOfYear",
            "_routing", "__FOXTROT_METADATA__.rawStorageId",
            "_type", "__FOXTROT_METADATA__.id", "date.hourOfDay",
            "_seq_no", "_field_names", "_source", "_id", "time", "_uid");
    assertTrue(ObjectUtils.equals(expectedFields, mappings.mappings().get(currentIndex).get(ElasticsearchUtils.DOCUMENT_TYPE_NAME).keySet()));
}
 
Example #5
Source File: ElasticSqlParseResult.java    From elasticsearch-sql with MIT License 4 votes vote down vote up
public GetFieldMappingsRequest getFieldMappingsRequest() {
    return fieldMappingsRequest;
}
 
Example #6
Source File: ElasticSqlParseResult.java    From elasticsearch-sql with MIT License 4 votes vote down vote up
public void setFieldMappingsRequest(GetFieldMappingsRequest fieldMappingsRequest) {
    this.fieldMappingsRequest = fieldMappingsRequest;
}
 
Example #7
Source File: ElasticsearchQueryStoreTest.java    From foxtrot with Apache License 2.0 4 votes vote down vote up
@Test
public void testSaveBulkNestedLargeTextNode() throws Exception {
    when(removerConfiguration.getBlockPercentage()).thenReturn(100);
    Table table = tableMetadataManager.get(TestUtils.TEST_TABLE_NAME);

    Document originalDocument = createLargeNestedDocumentWithLargeTextNodeAsKey();
    Document translatedDocument = TestUtils.translatedDocumentWithRowKeyVersion1(table, originalDocument);
    doReturn(translatedDocument).when(dataStore)
            .save(table, originalDocument);
    queryStore.save(TestUtils.TEST_TABLE_NAME, originalDocument);

    val currentIndex = ElasticsearchUtils.getCurrentIndex(TestUtils.TEST_TABLE_NAME, originalDocument.getTimestamp());

    String[] fields = {ElasticsearchUtils.DOCUMENT_META_TIMESTAMP_FIELD_NAME,
            "testField", String.format("testLargeField%s", StringUtils.repeat(".testField", 5))};
    val response = elasticsearchConnection.getClient()
            .prepareGet(currentIndex, ElasticsearchUtils.DOCUMENT_TYPE_NAME, originalDocument.getId())
            .setStoredFields(fields)
            .execute()
            .actionGet();
    assertTrue(response.isExists());

    val request = new GetFieldMappingsRequest();
    request.indices(currentIndex);
    request.fields("*");

    val mappings = elasticsearchConnection.getClient()
            .admin()
            .indices()
            .getFieldMappings(request)
            .get();

    Set<String> expectedFields = Sets.newHashSet("_index", "date.minuteOfHour", "date.year",
            "date.dayOfMonth", "testField", "testField.analyzed",
            "_all", "date.dayOfWeek", "date.minuteOfDay",
            "_parent", "date.monthOfYear", "__FOXTROT_METADATA__.time",
            "time.date", "_version", "date.weekOfYear",
            "_routing", "__FOXTROT_METADATA__.rawStorageId",
            "_type", "__FOXTROT_METADATA__.id", "date.hourOfDay",
            "_seq_no", "_field_names", "_source", "_id", "time", "_uid");
    assertTrue(ObjectUtils.equals(expectedFields, mappings.mappings().get(currentIndex).get(ElasticsearchUtils.DOCUMENT_TYPE_NAME).keySet()));
}
 
Example #8
Source File: ElasticsearchQueryStoreTest.java    From foxtrot with Apache License 2.0 4 votes vote down vote up
@Test
public void testSaveBulkNestedArrayLargeTextNode() throws Exception {
    when(removerConfiguration.getBlockPercentage()).thenReturn(100);
    Table table = tableMetadataManager.get(TestUtils.TEST_TABLE_NAME);

    Document originalDocument = createLargeNestedDocumentWithLargeTextNodeAsArrayValue();
    Document translatedDocument = TestUtils.translatedDocumentWithRowKeyVersion1(table, originalDocument);
    doReturn(translatedDocument).when(dataStore)
            .save(table, originalDocument);
    queryStore.save(TestUtils.TEST_TABLE_NAME, originalDocument);

    val currentIndex = ElasticsearchUtils.getCurrentIndex(TestUtils.TEST_TABLE_NAME, originalDocument.getTimestamp());

    String[] fields = {ElasticsearchUtils.DOCUMENT_META_TIMESTAMP_FIELD_NAME,
            "testField", String.format("testLargeField%s", StringUtils.repeat(".testField", 5))};
    val response = elasticsearchConnection.getClient()
            .prepareGet(currentIndex, ElasticsearchUtils.DOCUMENT_TYPE_NAME, originalDocument.getId())
            .setStoredFields(fields)
            .execute()
            .actionGet();
    assertTrue(response.isExists());

    val request = new GetFieldMappingsRequest();
    request.indices(currentIndex);
    request.fields("*");

    val mappings = elasticsearchConnection.getClient()
            .admin()
            .indices()
            .getFieldMappings(request)
            .get();
    val expectedFields = Sets.newHashSet("_index", "date.minuteOfHour", "date.year",
            "date.dayOfMonth", "testField", "testField.analyzed",
            "_all", "date.dayOfWeek", "date.minuteOfDay",
            "_parent", "date.monthOfYear", "__FOXTROT_METADATA__.time",
            "time.date", "_version", "date.weekOfYear",
            "_routing", "__FOXTROT_METADATA__.rawStorageId",
            "_type", "__FOXTROT_METADATA__.id", "date.hourOfDay",
            "_seq_no", "_field_names", "_source", "_id", "time", "_uid",
            "testLargeField.testField.testField.testField.testField_array", "testLargeField.testField.testField.testField.testField_array.analyzed");
    assertTrue(ObjectUtils.equals(expectedFields, mappings.mappings().get(currentIndex).get(ElasticsearchUtils.DOCUMENT_TYPE_NAME).keySet()));
}