try (JsonXContentParser parser = new JsonXContentParser(new NamedXContentRegistry(new SearchModule(Settings.EMPTY, true, Collections.emptyList()).getNamedXContents()), LoggingDeprecationHandler.INSTANCE, new JsonFactory().createParser(paramer.clauses))) { while (parser.nextToken() != XContentParser.Token.END_ARRAY) { QueryBuilder query = SpanNearQueryBuilder.parseInnerQueryBuilder(parser);
@Override public <T> T namedObject(Class<T> categoryClass, String name, Object context) throws IOException { return xContentRegistry.parseNamedObject(categoryClass, name, this, context); }
public RemoveCorruptedShardDataCommand(boolean translogOnly) { super("Removes corrupted shard files"); folderOption = parser.acceptsAll(Arrays.asList("d", "dir"), "Index directory location on disk") .withRequiredArg(); indexNameOption = parser.accepts("index", "Index name") .withRequiredArg(); shardIdOption = parser.accepts("shard-id", "Shard id") .withRequiredArg() .ofType(Integer.class); namedXContentRegistry = new NamedXContentRegistry(ClusterModule.getNamedXWriteables()); removeCorruptedLuceneSegmentsAction = translogOnly ? null : new RemoveCorruptedLuceneSegmentsAction(); truncateTranslogAction = new TruncateTranslogAction(namedXContentRegistry); }
@Override public <T> T namedObject(Class<T> categoryClass, String name, Object context) throws IOException { return xContentRegistry.parseNamedObject(categoryClass, name, this, context); }
.collect(Collectors.toList())); NamedWriteableRegistry namedWriteableRegistry = new NamedWriteableRegistry(entries); NamedXContentRegistry xContentRegistry = new NamedXContentRegistry(Stream.of( searchModule.getNamedXContents().stream(), pluginsService.filterPlugins(Plugin.class).stream()
@Override public <T> T namedObject(Class<T> categoryClass, String name, Object context) throws IOException { return xContentRegistry.parseNamedObject(categoryClass, name, this, context); }
.flatMap(Function.identity()).collect(Collectors.toList()); final NamedWriteableRegistry namedWriteableRegistry = new NamedWriteableRegistry(namedWriteables); NamedXContentRegistry xContentRegistry = new NamedXContentRegistry(Stream.of( NetworkModule.getNamedXContents().stream(), indicesModule.getNamedXContents().stream(),
/** * The {@link NamedXContentRegistry} to use for this test. Subclasses should override and use liberally. */ protected NamedXContentRegistry xContentRegistry() { return new NamedXContentRegistry(ClusterModule.getNamedXWriteables()); }
public SearchBase() { this.registry = new NamedXContentRegistry( Stream.of(getDefaultNamedXContents().stream(), getProvidedNamedXContents().stream(), new ArrayList<NamedXContentRegistry.Entry>().stream()) .flatMap(Function.identity()).collect(toList())); }
/** * Creates a {@link RestHighLevelClient} given the low level {@link RestClient} that it should use to perform requests and * a list of entries that allow to parse custom response sections added to Elasticsearch through plugins. * This constructor can be called by subclasses in case an externally created low-level REST client needs to be provided. * The consumer argument allows to control what needs to be done when the {@link #close()} method is called. * Also subclasses can provide parsers for custom response sections added to Elasticsearch through plugins. */ protected RestHighLevelClient(RestClient restClient, CheckedConsumer<RestClient, IOException> doClose, List<NamedXContentRegistry.Entry> namedXContentEntries) { this.client = Objects.requireNonNull(restClient, "restClient must not be null"); this.doClose = Objects.requireNonNull(doClose, "doClose consumer must not be null"); this.registry = new NamedXContentRegistry( Stream.of(getDefaultNamedXContents().stream(), getProvidedNamedXContents().stream(), namedXContentEntries.stream()) .flatMap(Function.identity()).collect(toList())); }
protected SearchSourceBuilder createSearchSourceBuilder(String query) { SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder(); SearchModule searchModule = new SearchModule(Settings.EMPTY, false, Collections.emptyList()); try { try (XContentParser parser = XContentFactory.xContent(XContentType.JSON).createParser( new NamedXContentRegistry(searchModule.getNamedXContents()), THROW_UNSUPPORTED_OPERATION, query)) { searchSourceBuilder.parseXContent(parser); } } catch (IOException | ParsingException e) { log.error("Invalid query: " + query + ": " + e.getMessage(), e); throw new IllegalArgumentException("Bad query: " + query); } return searchSourceBuilder; }
private SearchSourceBuilder toSearchSourceBuilder(JsonNode queryMap) throws ClientException { SearchSourceBuilder searchSourceBuilder = null; try { String content = queryMap.toString(); searchSourceBuilder = new SearchSourceBuilder(); SearchModule searchModule = new SearchModule(Settings.EMPTY, false, Collections.emptyList()); XContentParser parser = XContentFactory.xContent(XContentType.JSON) .createParser(new NamedXContentRegistry(searchModule.getNamedXContents()), content); searchSourceBuilder.parseXContent(new QueryParseContext(parser)); logger.debug("Search builder: {}", searchSourceBuilder); return searchSourceBuilder; } catch (Throwable t) { throw new ClientException(ClientErrorCodes.ACTION_ERROR, t, CLIENT_QUERY_PARSING_ERROR_MSG); } }
private SearchSourceBuilder toSearchSourceBuilder(JsonNode queryMap) throws ClientException { SearchSourceBuilder searchSourceBuilder = null; try { String content = queryMap.toString(); searchSourceBuilder = new SearchSourceBuilder(); SearchModule searchModule = new SearchModule(Settings.EMPTY, false, Collections.emptyList()); XContentParser parser = XContentFactory.xContent(XContentType.JSON) .createParser(new NamedXContentRegistry(searchModule.getNamedXContents()), content); searchSourceBuilder.parseXContent(new QueryParseContext(parser)); logger.debug("Search builder: {}", searchSourceBuilder); return searchSourceBuilder; } catch (Throwable t) { throw new ClientException(ClientErrorCodes.ACTION_ERROR, t, CLIENT_QUERY_PARSING_ERROR_MSG); } }
@Override protected NamedXContentRegistry xContentRegistry() { if (isInternalCluster() && cluster().size() > 0) { // If it's internal cluster - using existing registry in case plugin registered custom data return internalCluster().getInstance(NamedXContentRegistry.class); } else { // If it's external cluster - fall back to the standard set return new NamedXContentRegistry(ClusterModule.getNamedXWriteables()); } }
/** * Setup for the whole base test class. */ @Override public void setUp() throws Exception { super.setUp(); Settings settings = Settings.builder() .put("node.name", AbstractQueryTestCase.class.toString()) .put(Environment.PATH_HOME_SETTING.getKey(), createTempDir()) .build(); IndicesModule indicesModule = new IndicesModule(Collections.emptyList()); PluginsService pluginsService = new PluginsService(settings, null, null, null, getPlugins()); SearchModule searchModule = new SearchModule(settings, false, pluginsService.filterPlugins(SearchPlugin.class)); List<NamedWriteableRegistry.Entry> entries = new ArrayList<>(); entries.addAll(indicesModule.getNamedWriteables()); entries.addAll(searchModule.getNamedWriteables()); namedWriteableRegistry = new NamedWriteableRegistry(entries); xContentRegistry = new NamedXContentRegistry(searchModule.getNamedXContents()); //create some random type with some default field, those types will stick around for all of the subclasses currentTypes = new String[randomIntBetween(0, 5)]; for (int i = 0; i < currentTypes.length; i++) { String type = randomAlphaOfLengthBetween(1, 10); currentTypes[i] = type; } }
public RemoveCorruptedShardDataCommand(boolean translogOnly) { super("Removes corrupted shard files"); folderOption = parser.acceptsAll(Arrays.asList("d", "dir"), "Index directory location on disk") .withRequiredArg(); indexNameOption = parser.accepts("index", "Index name") .withRequiredArg(); shardIdOption = parser.accepts("shard-id", "Shard id") .withRequiredArg() .ofType(Integer.class); namedXContentRegistry = new NamedXContentRegistry(ClusterModule.getNamedXWriteables()); removeCorruptedLuceneSegmentsAction = translogOnly ? null : new RemoveCorruptedLuceneSegmentsAction(); truncateTranslogAction = new TruncateTranslogAction(namedXContentRegistry); }
public RemoveCorruptedShardDataCommand(boolean translogOnly) { super("Removes corrupted shard files"); folderOption = parser.acceptsAll(Arrays.asList("d", "dir"), "Index directory location on disk") .withRequiredArg(); indexNameOption = parser.accepts("index", "Index name") .withRequiredArg(); shardIdOption = parser.accepts("shard-id", "Shard id") .withRequiredArg() .ofType(Integer.class); namedXContentRegistry = new NamedXContentRegistry(ClusterModule.getNamedXWriteables()); removeCorruptedLuceneSegmentsAction = translogOnly ? null : new RemoveCorruptedLuceneSegmentsAction(); truncateTranslogAction = new TruncateTranslogAction(namedXContentRegistry); }
new SearchModule(Settings.EMPTY, false, emptyList()).getNamedWriteables()); private final NamedXContentRegistry namedXContentRegistry = new NamedXContentRegistry(getNamedXContents());
.collect(Collectors.toList())); NamedWriteableRegistry namedWriteableRegistry = new NamedWriteableRegistry(entries); NamedXContentRegistry xContentRegistry = new NamedXContentRegistry(Stream.of( searchModule.getNamedXContents().stream(), pluginsService.filterPlugins(Plugin.class).stream()
.collect(Collectors.toList())); NamedWriteableRegistry namedWriteableRegistry = new NamedWriteableRegistry(entries); NamedXContentRegistry xContentRegistry = new NamedXContentRegistry(Stream.of( searchModule.getNamedXContents().stream(), pluginsService.filterPlugins(Plugin.class).stream()