Java Code Examples for org.elasticsearch.action.admin.indices.mapping.get.GetMappingsRequest#indices()

The following examples show how to use org.elasticsearch.action.admin.indices.mapping.get.GetMappingsRequest#indices() . 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: ElasticsearchUtil.java    From adaptive-alerting with Apache License 2.0 6 votes vote down vote up
@Generated
public Set<String> removeFieldsHavingExistingMapping(Set<String> fields, String indexName, String docType) {
    GetMappingsRequest request = new GetMappingsRequest();
    request.indices(indexName);

    try {
        GetMappingsResponse mappingsResponse = legacyElasticSearchClient.indices().getMapping(request, RequestOptions.DEFAULT);
        Map<String, String> mapProperties = ((Map<String, String>) mappingsResponse.getMappings()
                .get(indexName)
                .get(docType)
                .sourceAsMap().get("properties"));

        Set<String> mappedFields = new HashSet<>(mapProperties.keySet());
        fields.removeAll(mappedFields);
        return fields;
    } catch (IOException e) {
        log.error("Error finding mappings", e);
        throw new RuntimeException(e);
    }
}
 
Example 3
Source File: RequestConvertersExt.java    From canal with Apache License 2.0 3 votes vote down vote up
/**
 * 修改 getMappings 去掉request参数
 *
 * @param getMappingsRequest
 * @return
 * @throws IOException
 */
static Request getMappings(GetMappingsRequest getMappingsRequest) throws IOException {
    String[] indices = getMappingsRequest.indices() == null ? Strings.EMPTY_ARRAY : getMappingsRequest.indices();
    String[] types = getMappingsRequest.types() == null ? Strings.EMPTY_ARRAY : getMappingsRequest.types();

    return new Request(HttpGet.METHOD_NAME, RequestConverters.endpoint(indices, "_mapping", types));
}