org.elasticsearch.common.xcontent.NamedXContentRegistry Java Examples

The following examples show how to use org.elasticsearch.common.xcontent.NamedXContentRegistry. 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: XGBoostJsonParser.java    From elasticsearch-learning-to-rank with Apache License 2.0 6 votes vote down vote up
@Override
public NaiveAdditiveDecisionTree parse(FeatureSet set, String model) {
    XGBoostDefinition modelDefinition;
    try (XContentParser parser = JsonXContent.jsonXContent.createParser(NamedXContentRegistry.EMPTY,
            LoggingDeprecationHandler.INSTANCE, model)
    ) {
        modelDefinition = XGBoostDefinition.parse(parser, set);
    } catch (IOException e) {
        throw new IllegalArgumentException("Cannot parse model", e);
    }

    Node[] trees = modelDefinition.getTrees(set);
    float[] weights = new float[trees.length];
    // Tree weights are already encoded in outputs
    Arrays.fill(weights, 1F);
    return new NaiveAdditiveDecisionTree(trees, weights, set.size(), modelDefinition.normalizer);
}
 
Example #2
Source File: JsonXContentGenerator.java    From crate with Apache License 2.0 6 votes vote down vote up
@Override
public void writeRawField(String name, InputStream content, XContentType contentType) throws IOException {
    if (mayWriteRawData(contentType) == false) {
        // EMPTY is safe here because we never call namedObject when writing raw data
        try (XContentParser parser = XContentFactory.xContent(contentType)
                // It's okay to pass the throwing deprecation handler
                // because we should not be writing raw fields when
                // generating JSON
                .createParser(NamedXContentRegistry.EMPTY, DeprecationHandler.THROW_UNSUPPORTED_OPERATION, content)) {
            parser.nextToken();
            writeFieldName(name);
            copyCurrentStructure(parser);
        }
    } else {
        writeStartRaw(name);
        flush();
        copyStream(content, os);
        writeEndRaw();
    }
}
 
Example #3
Source File: MetaDataIndexUpgradeService.java    From crate with Apache License 2.0 6 votes vote down vote up
public MetaDataIndexUpgradeService(Settings settings,
                                   NamedXContentRegistry xContentRegistry,
                                   MapperRegistry mapperRegistry,
                                   IndexScopedSettings indexScopedSettings,
                                   Collection<UnaryOperator<IndexMetaData>> indexMetaDataUpgraders) {
    this.settings = settings;
    this.xContentRegistry = xContentRegistry;
    this.mapperRegistry = mapperRegistry;
    this.indexScopedSettings = indexScopedSettings;
    this.upgraders = indexMetaData -> {
        IndexMetaData newIndexMetaData = indexMetaData;
        for (UnaryOperator<IndexMetaData> upgrader : indexMetaDataUpgraders) {
            newIndexMetaData = upgrader.apply(newIndexMetaData);
        }
        return newIndexMetaData;
    };
}
 
Example #4
Source File: MapperTestUtils.java    From crate with Apache License 2.0 6 votes vote down vote up
public static MapperService newMapperService(NamedXContentRegistry xContentRegistry, Path tempDir, Settings settings,
                                             IndicesModule indicesModule, String indexName) throws IOException {
    Settings.Builder settingsBuilder = Settings.builder()
        .put(Environment.PATH_HOME_SETTING.getKey(), tempDir)
        .put(settings);
    if (settings.get(IndexMetaData.SETTING_VERSION_CREATED) == null) {
        settingsBuilder.put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT);
    }
    Settings finalSettings = settingsBuilder.build();
    MapperRegistry mapperRegistry = indicesModule.getMapperRegistry();
    IndexSettings indexSettings = IndexSettingsModule.newIndexSettings(indexName, finalSettings);
    IndexAnalyzers indexAnalyzers = createTestAnalysis(indexSettings, finalSettings).indexAnalyzers;
    return new MapperService(indexSettings,
        indexAnalyzers,
        xContentRegistry,
        mapperRegistry,
        () -> null);
}
 
Example #5
Source File: OpenDistroSecuritySSLPlugin.java    From deprecated-security-ssl with Apache License 2.0 6 votes vote down vote up
@Override
public Map<String, Supplier<HttpServerTransport>> getHttpTransports(Settings settings, ThreadPool threadPool, BigArrays bigArrays,
        CircuitBreakerService circuitBreakerService, NamedWriteableRegistry namedWriteableRegistry,
        NamedXContentRegistry xContentRegistry, NetworkService networkService, Dispatcher dispatcher) {
    
    final Map<String, Supplier<HttpServerTransport>> httpTransports = new HashMap<String, Supplier<HttpServerTransport>>(1);
    if (!client && httpSSLEnabled) {
        
        final ValidatingDispatcher validatingDispatcher = new ValidatingDispatcher(threadPool.getThreadContext(), dispatcher, settings, configPath, NOOP_SSL_EXCEPTION_HANDLER);
        final OpenDistroSecuritySSLNettyHttpServerTransport sgsnht = new OpenDistroSecuritySSLNettyHttpServerTransport(settings, networkService, bigArrays, threadPool, odsks, xContentRegistry, validatingDispatcher, NOOP_SSL_EXCEPTION_HANDLER);
        
        httpTransports.put("com.amazon.opendistroforelasticsearch.security.ssl.http.netty.OpenDistroSecuritySSLNettyHttpServerTransport", () -> sgsnht);
        
    }
    return httpTransports;
}
 
Example #6
Source File: S3RepositoryPlugin.java    From crate with Apache License 2.0 6 votes vote down vote up
@Override
public Map<String, Repository.Factory> getRepositories(final Environment env, final NamedXContentRegistry registry, ThreadPool threadPool) {
    return Collections.singletonMap(
        S3Repository.TYPE,
        new Repository.Factory() {

            @Override
            public TypeSettings settings() {
                return new TypeSettings(List.of(), S3Repository.optionalSettings());
            }

            @Override
            public Repository create(RepositoryMetaData metadata) throws Exception {
                return new S3Repository(metadata, env.settings(), registry, service, threadPool);
            }
        }
    );
}
 
Example #7
Source File: GeoUtils.java    From crate with Apache License 2.0 6 votes vote down vote up
/**
 * Parses the value as a geopoint. The following types of values are supported:
 * <p>
 * Object: has to contain either lat and lon or geohash fields
 * <p>
 * String: expected to be in "latitude, longitude" format or a geohash
 * <p>
 * Array: two or more elements, the first element is longitude, the second is latitude, the rest is ignored if ignoreZValue is true
 */
public static GeoPoint parseGeoPoint(Object value, final boolean ignoreZValue) throws ElasticsearchParseException {
    try {
        XContentBuilder content = JsonXContent.contentBuilder();
        content.startObject();
        content.field("null_value", value);
        content.endObject();

        try (InputStream stream = BytesReference.bytes(content).streamInput();
             XContentParser parser = JsonXContent.JSON_XCONTENT.createParser(
                 NamedXContentRegistry.EMPTY, LoggingDeprecationHandler.INSTANCE, stream)) {
            parser.nextToken(); // start object
            parser.nextToken(); // field name
            parser.nextToken(); // field value
            return parseGeoPoint(parser, new GeoPoint(), ignoreZValue);
        }

    } catch (IOException ex) {
        throw new ElasticsearchParseException("error parsing geopoint", ex);
    }
}
 
Example #8
Source File: TransportNodesListShardStoreMetaData.java    From crate with Apache License 2.0 6 votes vote down vote up
@Inject
public TransportNodesListShardStoreMetaData(Settings settings,
                                            ThreadPool threadPool,
                                            ClusterService clusterService,
                                            TransportService transportService,
                                            IndicesService indicesService,
                                            NodeEnvironment nodeEnv,
                                            IndexNameExpressionResolver indexNameExpressionResolver,
                                            NamedXContentRegistry namedXContentRegistry) {
    super(ACTION_NAME, threadPool, clusterService, transportService, indexNameExpressionResolver,
        Request::new, NodeRequest::new, ThreadPool.Names.FETCH_SHARD_STORE, NodeStoreFilesMetaData.class);
    this.settings = settings;
    this.indicesService = indicesService;
    this.nodeEnv = nodeEnv;
    this.namedXContentRegistry = namedXContentRegistry;
}
 
Example #9
Source File: ParseUtils.java    From anomaly-detection with Apache License 2.0 6 votes vote down vote up
public static SearchSourceBuilder generatePreviewQuery(
    AnomalyDetector detector,
    List<Entry<Long, Long>> ranges,
    NamedXContentRegistry xContentRegistry
) throws IOException {

    DateRangeAggregationBuilder dateRangeBuilder = dateRange("date_range").field(detector.getTimeField()).format("epoch_millis");
    for (Entry<Long, Long> range : ranges) {
        dateRangeBuilder.addRange(range.getKey(), range.getValue());
    }

    if (detector.getFeatureAttributes() != null) {
        for (Feature feature : detector.getFeatureAttributes()) {
            AggregatorFactories.Builder internalAgg = parseAggregators(
                feature.getAggregation().toString(),
                xContentRegistry,
                feature.getId()
            );
            dateRangeBuilder.subAggregation(internalAgg.getAggregatorFactories().iterator().next());
        }
    }

    return new SearchSourceBuilder().query(detector.getFilterQuery()).size(0).aggregation(dateRangeBuilder);
}
 
Example #10
Source File: ParseUtils.java    From anomaly-detection with Apache License 2.0 6 votes vote down vote up
public static String generateInternalFeatureQueryTemplate(AnomalyDetector detector, NamedXContentRegistry xContentRegistry)
    throws IOException {
    RangeQueryBuilder rangeQuery = new RangeQueryBuilder(detector.getTimeField())
        .from("{{" + QUERY_PARAM_PERIOD_START + "}}")
        .to("{{" + QUERY_PARAM_PERIOD_END + "}}");

    BoolQueryBuilder internalFilterQuery = QueryBuilders.boolQuery().must(rangeQuery).must(detector.getFilterQuery());

    SearchSourceBuilder internalSearchSourceBuilder = new SearchSourceBuilder().query(internalFilterQuery);
    if (detector.getFeatureAttributes() != null) {
        for (Feature feature : detector.getFeatureAttributes()) {
            AggregatorFactories.Builder internalAgg = parseAggregators(
                feature.getAggregation().toString(),
                xContentRegistry,
                feature.getId()
            );
            internalSearchSourceBuilder.aggregation(internalAgg.getAggregatorFactories().iterator().next());
        }
    }

    return internalSearchSourceBuilder.toString();
}
 
Example #11
Source File: SampleIndexTestCase.java    From elasticsearch-carrot2 with Apache License 2.0 6 votes vote down vote up
/**
 * Roundtrip to/from JSON.
 */
protected static void checkJsonSerialization(ClusteringActionResponse result) throws IOException {
   XContentBuilder builder = XContentFactory.jsonBuilder().prettyPrint();
   builder.startObject();
   result.toXContent(builder, ToXContent.EMPTY_PARAMS);
   builder.endObject();
   String json = Strings.toString(builder);

   try (XContentParser parser = JsonXContent.jsonXContent.createParser(NamedXContentRegistry.EMPTY,
       DeprecationHandler.THROW_UNSUPPORTED_OPERATION, json)) {
      Map<String, Object> mapAndClose = parser.map();
      Assertions.assertThat(mapAndClose)
          .as("json-result")
          .containsKey(Fields.CLUSTERS);
   }
}
 
Example #12
Source File: PartitionedTableIntegrationTest.java    From crate with Apache License 2.0 6 votes vote down vote up
@Test
@UseRandomizedSchema(random = false)
public void testAlterTableAddColumnOnPartitionedTableWithoutPartitions() throws Exception {
    execute("create table t (id int primary key, date timestamp with time zone primary key) " +
            "partitioned by (date) " +
            "clustered into 1 shards " +
            "with (number_of_replicas=0)");
    ensureYellow();

    execute("alter table t add column name string");
    execute("alter table t add column ft_name string index using fulltext");
    ensureYellow();

    execute("select * from t");
    assertThat(Arrays.asList(response.cols()), Matchers.containsInAnyOrder("date", "ft_name", "id", "name"));

    GetIndexTemplatesResponse templatesResponse = client().admin().indices().getTemplates(new GetIndexTemplatesRequest(".partitioned.t.")).actionGet();
    IndexTemplateMetaData metaData = templatesResponse.getIndexTemplates().get(0);
    String mappingSource = metaData.mappings().get(DEFAULT_MAPPING_TYPE).toString();
    Map mapping = (Map) XContentFactory.xContent(mappingSource)
        .createParser(NamedXContentRegistry.EMPTY, DeprecationHandler.THROW_UNSUPPORTED_OPERATION, mappingSource)
        .map()
        .get(DEFAULT_MAPPING_TYPE);
    assertNotNull(((Map) mapping.get("properties")).get("name"));
    assertNotNull(((Map) mapping.get("properties")).get("ft_name"));
}
 
Example #13
Source File: MetaDataStateFormat.java    From crate with Apache License 2.0 6 votes vote down vote up
/**
 * Tries to load the latest state from the given data-locations.
 *
 * @param logger        a logger instance.
 * @param dataLocations the data-locations to try.
 * @return tuple of the latest state and generation. (-1, null) if no state is found.
 */
public Tuple<T, Long> loadLatestStateWithGeneration(Logger logger, NamedXContentRegistry namedXContentRegistry, Path... dataLocations)
        throws IOException {
    long generation = findMaxGenerationId(prefix, dataLocations);
    T state = loadGeneration(logger, namedXContentRegistry, generation, dataLocations);

    if (generation > -1 && state == null) {
        throw new IllegalStateException(
            "unable to find state files with generation id " + generation +
            " returned by findMaxGenerationId function, in data folders [" +
            Arrays.stream(dataLocations)
                .map(Path::toAbsolutePath)
                .map(Object::toString)
                .collect(Collectors.joining(", ")) + "], concurrent writes?");
    }
    return Tuple.tuple(state, generation);
}
 
Example #14
Source File: AzureRepository.java    From crate with Apache License 2.0 6 votes vote down vote up
public AzureRepository(RepositoryMetaData metadata,
                       Environment environment,
                       NamedXContentRegistry namedXContentRegistry,
                       AzureStorageService storageService,
                       ThreadPool threadPool) {
    super(metadata, environment.settings(), namedXContentRegistry, threadPool, buildBasePath(metadata));
    this.chunkSize = Repository.CHUNK_SIZE_SETTING.get(metadata.settings());
    this.storageService = storageService;

    // If the user explicitly did not define a readonly value, we set it by ourselves depending on the location mode setting.
    // For secondary_only setting, the repository should be read only
    final LocationMode locationMode = Repository.LOCATION_MODE_SETTING.get(metadata.settings());
    if (Repository.READONLY_SETTING.exists(metadata.settings())) {
        this.readonly = Repository.READONLY_SETTING.get(metadata.settings());
    } else {
        this.readonly = locationMode == LocationMode.SECONDARY_ONLY;
    }
}
 
Example #15
Source File: Netty4Plugin.java    From crate with Apache License 2.0 6 votes vote down vote up
@Override
public Map<String, Supplier<HttpServerTransport>> getHttpTransports(Settings settings, ThreadPool threadPool, BigArrays bigArrays,
                                                                    CircuitBreakerService circuitBreakerService,
                                                                    NamedWriteableRegistry namedWriteableRegistry,
                                                                    NamedXContentRegistry xContentRegistry,
                                                                    NetworkService networkService,
                                                                    NodeClient nodeClient) {
    return Collections.singletonMap(
        NETTY_HTTP_TRANSPORT_NAME,
        () -> new Netty4HttpServerTransport(
            settings,
            networkService,
            bigArrays,
            threadPool,
            xContentRegistry,
            pipelineRegistry,
            nodeClient
        )
    );
}
 
Example #16
Source File: LtrQueryParserPlugin.java    From elasticsearch-learning-to-rank with Apache License 2.0 6 votes vote down vote up
@Override
public Collection<Object> createComponents(Client client,
                                           ClusterService clusterService,
                                           ThreadPool threadPool,
                                           ResourceWatcherService resourceWatcherService,
                                           ScriptService scriptService,
                                           NamedXContentRegistry xContentRegistry,
                                           Environment environment,
                                           NodeEnvironment nodeEnvironment,
                                           NamedWriteableRegistry namedWriteableRegistry,
                                           IndexNameExpressionResolver indexNameExpressionResolver) {
    clusterService.addListener(event -> {
        for (Index i : event.indicesDeleted()) {
            if (IndexFeatureStore.isIndexStore(i.getName())) {
                caches.evict(i.getName());
            }
        }
    });
    return asList(caches, parserFactory);
}
 
Example #17
Source File: Settings.java    From crate with Apache License 2.0 5 votes vote down vote up
/**
 * Loads settings from the actual string content that represents them using {@link #fromXContent(XContentParser)}
 */
public Builder loadFromSource(String source, XContentType xContentType) {
    try (XContentParser parser = XContentFactory.xContent(xContentType)
            .createParser(NamedXContentRegistry.EMPTY, LoggingDeprecationHandler.INSTANCE, source)) {
        this.put(fromXContent(parser, true, true));
    } catch (Exception e) {
        throw new SettingsException("Failed to load settings from [" + source + "]", e);
    }
    return this;
}
 
Example #18
Source File: JsonXContentGenerator.java    From crate with Apache License 2.0 5 votes vote down vote up
protected void copyRawValue(InputStream stream, XContent xContent) throws IOException {
    // EMPTY is safe here because we never call namedObject
    try (XContentParser parser = xContent
             // It's okay to pass the throwing deprecation handler because we
             // should not be writing raw fields when generating JSON
             .createParser(NamedXContentRegistry.EMPTY, DeprecationHandler.THROW_UNSUPPORTED_OPERATION, stream)) {
        copyCurrentStructure(parser);
    }
}
 
Example #19
Source File: DlsFlsValveImpl.java    From deprecated-security-advanced-modules with Apache License 2.0 5 votes vote down vote up
@Override
public void handleSearchContext(SearchContext context, ThreadPool threadPool, NamedXContentRegistry namedXContentRegistry) {
    try {
        final Map<String, Set<String>> queries = (Map<String, Set<String>>) HeaderHelper.deserializeSafeFromHeader(threadPool.getThreadContext(),
                ConfigConstants.OPENDISTRO_SECURITY_DLS_QUERY_HEADER);

        final String dlsEval = OpenDistroSecurityUtils.evalMap(queries, context.indexShard().indexSettings().getIndex().getName());

        if (dlsEval != null) {

            if(context.suggest() != null) {
                return;
            }

            assert context.parsedQuery() != null;

            final Set<String> unparsedDlsQueries = queries.get(dlsEval);
            if (unparsedDlsQueries != null && !unparsedDlsQueries.isEmpty()) {
                final ParsedQuery dlsQuery = DlsQueryParser.parse(unparsedDlsQueries, context.parsedQuery(), context.getQueryShardContext(), namedXContentRegistry);
                context.parsedQuery(dlsQuery);
                context.preProcess(true);
            }
        }
    } catch (Exception e) {
        throw new RuntimeException("Error evaluating dls for a search query: " + e, e);
    }

}
 
Example #20
Source File: DDLClusterStateHelpers.java    From crate with Apache License 2.0 5 votes vote down vote up
private static Map<String, Object> parseMapping(String mappingSource) {
    try (XContentParser parser = JsonXContent.JSON_XCONTENT
        .createParser(NamedXContentRegistry.EMPTY, DeprecationHandler.THROW_UNSUPPORTED_OPERATION, mappingSource)) {
        return parser.map();
    } catch (IOException e) {
        throw new ElasticsearchException("failed to parse mapping");
    }
}
 
Example #21
Source File: NetworkPlugin.java    From crate with Apache License 2.0 5 votes vote down vote up
/**
 * Returns a map of {@link HttpServerTransport} suppliers.
 * See {@link org.elasticsearch.common.network.NetworkModule#HTTP_TYPE_SETTING} to configure a specific implementation.
 */
default Map<String, Supplier<HttpServerTransport>> getHttpTransports(Settings settings,
                                                                     ThreadPool threadPool,
                                                                     BigArrays bigArrays,
                                                                     CircuitBreakerService circuitBreakerService,
                                                                     NamedWriteableRegistry namedWriteableRegistry,
                                                                     NamedXContentRegistry xContentRegistry,
                                                                     NetworkService networkService,
                                                                     NodeClient nodeClient) {
    return Collections.emptyMap();
}
 
Example #22
Source File: JsonType.java    From crate with Apache License 2.0 5 votes vote down vote up
@Override
Object decodeUTF8Text(byte[] bytes) {
    try {
        XContentParser parser = JsonXContent.JSON_XCONTENT.createParser(
            NamedXContentRegistry.EMPTY, DeprecationHandler.THROW_UNSUPPORTED_OPERATION, bytes);
        if (bytes.length > 1 && bytes[0] == '[') {
            parser.nextToken();
            return parser.list();
        }
        return parser.map();
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}
 
Example #23
Source File: PutIndexTemplateRequest.java    From crate with Apache License 2.0 5 votes vote down vote up
/**
 * Sets the aliases that will be associated with the index when it gets created
 */
public PutIndexTemplateRequest aliases(BytesReference source) {
    // EMPTY is safe here because we never call namedObject
    try (XContentParser parser = XContentHelper
            .createParser(NamedXContentRegistry.EMPTY, LoggingDeprecationHandler.INSTANCE, source)) {
        //move to the first alias
        parser.nextToken();
        while ((parser.nextToken()) != XContentParser.Token.END_OBJECT) {
            alias(Alias.fromXContent(parser));
        }
        return this;
    } catch (IOException e) {
        throw new ElasticsearchParseException("Failed to parse aliases", e);
    }
}
 
Example #24
Source File: MapperTestUtils.java    From crate with Apache License 2.0 5 votes vote down vote up
public static MapperService newMapperService(NamedXContentRegistry xContentRegistry,
                                             Path tempDir,
                                             Settings indexSettings,
                                             String indexName) throws IOException {
    IndicesModule indicesModule = new IndicesModule(Collections.emptyList());
    return newMapperService(xContentRegistry, tempDir, indexSettings, indicesModule, indexName);
}
 
Example #25
Source File: OpenShiftElasticSearchPlugin.java    From openshift-elasticsearch-plugin with Apache License 2.0 5 votes vote down vote up
@Override
public Collection<Object> createComponents(Client client, ClusterService clusterService, ThreadPool threadPool,
        ResourceWatcherService resourceWatcherService, ScriptService scriptService,
        NamedXContentRegistry namedXContentRegistry) {

    final PluginSettings pluginSettings = new PluginSettings(settings);
    final IndexMappingLoader indexMappingLoader = new IndexMappingLoader(settings);
    final PluginClient pluginClient = new PluginClient(client, threadPool.getThreadContext());
    final OpenshiftAPIService apiService = new OpenshiftAPIService();
    final RequestUtils requestUtils = new RequestUtils(pluginSettings, apiService);
    final OpenshiftRequestContextFactory contextFactory = new OpenshiftRequestContextFactory(settings, requestUtils,
            apiService, threadPool.getThreadContext());
    final SearchGuardSyncStrategyFactory documentFactory = new SearchGuardSyncStrategyFactory(pluginSettings);
    final KibanaUtils kUtils = new KibanaUtils(pluginSettings, pluginClient);
    final KibanaSeed seed = new KibanaSeed(pluginSettings, indexMappingLoader, pluginClient, kUtils);
    final ACLDocumentManager aclDocumentManager = new ACLDocumentManager(pluginClient, pluginSettings, documentFactory, threadPool);
    this.aclFilter = new DynamicACLFilter(pluginSettings, seed, client, threadPool, requestUtils, aclDocumentManager);
    
    PluginServiceFactory.setApiService(apiService);
    PluginServiceFactory.setContextFactory(contextFactory);
    PluginServiceFactory.setThreadContext(threadPool.getThreadContext());
    PluginServiceFactory.markReady();

    List<Object> list = new ArrayList<>();
    list.add(aclDocumentManager);
    list.add(pluginSettings);
    list.add(indexMappingLoader);
    list.add(pluginClient);
    list.add(requestUtils);
    list.add(apiService);
    list.add(contextFactory);
    list.add(documentFactory);
    list.add(kUtils);
    list.add(seed);
    list.add(aclFilter);
    list.add(new FieldStatsResponseFilter(pluginClient));
    list.addAll(sgPlugin.createComponents(client, clusterService, threadPool, resourceWatcherService, scriptService,
            namedXContentRegistry));
    return list;
}
 
Example #26
Source File: DocumentMapperParser.java    From crate with Apache License 2.0 5 votes vote down vote up
public DocumentMapperParser(IndexSettings indexSettings, MapperService mapperService, IndexAnalyzers indexAnalyzers,
                            NamedXContentRegistry xContentRegistry, MapperRegistry mapperRegistry,
                            Supplier<QueryShardContext> queryShardContextSupplier) {
    this.mapperService = mapperService;
    this.indexAnalyzers = indexAnalyzers;
    this.xContentRegistry = xContentRegistry;
    this.queryShardContextSupplier = queryShardContextSupplier;
    this.typeParsers = mapperRegistry.getMapperParsers();
    this.rootTypeParsers = mapperRegistry.getMetadataMapperParsers();
    indexVersionCreated = indexSettings.getIndexVersionCreated();
}
 
Example #27
Source File: TranslogHandler.java    From crate with Apache License 2.0 5 votes vote down vote up
public TranslogHandler(NamedXContentRegistry xContentRegistry, IndexSettings indexSettings) {
    NamedAnalyzer defaultAnalyzer = new NamedAnalyzer("default", AnalyzerScope.INDEX, new StandardAnalyzer());
    IndexAnalyzers indexAnalyzers =
            new IndexAnalyzers(indexSettings, defaultAnalyzer, defaultAnalyzer, defaultAnalyzer, emptyMap(), emptyMap(), emptyMap());
    MapperRegistry mapperRegistry = new IndicesModule(emptyList()).getMapperRegistry();
    mapperService = new MapperService(indexSettings, indexAnalyzers, xContentRegistry, mapperRegistry,
            () -> null);
}
 
Example #28
Source File: GeoJSONUtils.java    From crate with Apache License 2.0 5 votes vote down vote up
private static Shape geoJSONString2Shape(String geoJSON) {
    try {
        XContentParser parser = JsonXContent.JSON_XCONTENT.createParser(
            NamedXContentRegistry.EMPTY, DeprecationHandler.THROW_UNSUPPORTED_OPERATION, geoJSON);
        parser.nextToken();
        return ShapeParser.parse(parser).build();
    } catch (Throwable t) {
        throw new IllegalArgumentException(String.format(Locale.ENGLISH,
            "Cannot convert GeoJSON \"%s\" to shape", geoJSON), t);
    }
}
 
Example #29
Source File: NodeEnvironment.java    From crate with Apache License 2.0 5 votes vote down vote up
/**
 * scans the node paths and loads existing metaData file. If not found a new meta data will be generated
 * and persisted into the nodePaths
 */
private static NodeMetaData loadOrCreateNodeMetaData(Settings settings, Logger logger,
                                                     NodePath... nodePaths) throws IOException {
    final Path[] paths = Arrays.stream(nodePaths).map(np -> np.path).toArray(Path[]::new);
    NodeMetaData metaData = NodeMetaData.FORMAT.loadLatestState(logger, NamedXContentRegistry.EMPTY, paths);
    if (metaData == null) {
        metaData = new NodeMetaData(generateNodeId(settings));
    }
    // we write again to make sure all paths have the latest state file
    NodeMetaData.FORMAT.writeAndCleanup(metaData, paths);
    return metaData;
}
 
Example #30
Source File: OpenShiftRestResponseTest.java    From openshift-elasticsearch-plugin with Apache License 2.0 5 votes vote down vote up
@Test
public void testSearchResponse() throws Exception {
    
    String body = "{\"took\":10,\"timed_out\":false,\"_shards\":{\"total\":5,\"successful\":5,\"skipped\":0,\"failed\":0},"
            + "\"hits\":{\"total\":2,\"max_score\":1.0,\"hits\":[{\"_index\":\"%1$s\",\"_type\":\"config\",\"_id\":\"0\","
            + "\"_score\":1.0,\"_source\":{\"key\":\"value\",\"version\":\"5.6.10\"}},{\"_index\":\"%1$s\",\"_type\":\"config\","
            + "\"_id\":\"2\",\"_score\":1.0,\"_source\":{\"key\":\"value\",\"version\":\"5.6.10\"}}]}}";
    
    XContentParser parser = XCONTENT.createParser(NamedXContentRegistry.EMPTY, String.format(body, KIBANA_INDEX));
    SearchResponse actionResponse = SearchResponse.fromXContent(parser);
    
    OpenShiftRestResponse osResponse = whenCreatingResponseResponse(actionResponse);
    thenResponseShouldBeModified(osResponse, body);
}