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);
NamedWriteableRegistry namedWriteableRegistry = new NamedWriteableRegistry(entries); NamedXContentRegistry xContentRegistry = new NamedXContentRegistry(Stream.of( searchModule.getNamedXContents().stream(), pluginsService.filterPlugins(Plugin.class).stream() .flatMap(p -> p.getNamedXContent().stream())
NetworkModule.getNamedXContents().stream(), indicesModule.getNamedXContents().stream(), searchModule.getNamedXContents().stream(), pluginsService.filterPlugins(Plugin.class).stream() .flatMap(p -> p.getNamedXContent().stream()),
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); } }
/** * 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; } }
NamedWriteableRegistry namedWriteableRegistry = new NamedWriteableRegistry(entries); NamedXContentRegistry xContentRegistry = new NamedXContentRegistry(Stream.of( searchModule.getNamedXContents().stream(), pluginsService.filterPlugins(Plugin.class).stream() .flatMap(p -> p.getNamedXContent().stream())
NamedWriteableRegistry namedWriteableRegistry = new NamedWriteableRegistry(entries); NamedXContentRegistry xContentRegistry = new NamedXContentRegistry(Stream.of( searchModule.getNamedXContents().stream(), pluginsService.filterPlugins(Plugin.class).stream() .flatMap(p -> p.getNamedXContent().stream())
/** * Submit a search query to Elasticsearch. * * @param indexName The name of the index to search. * @param query The query to search. * @return The search response returned by Elasticsearch. * @throws IOException */ private SearchResponse search(String indexName, String query) throws IOException { SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder(); SearchModule searchModule = new SearchModule(Settings.EMPTY, false, Collections.emptyList()); try (XContentParser parser = XContentFactory.xContent(XContentType.JSON).createParser(new NamedXContentRegistry(searchModule .getNamedXContents()), DeprecationHandler.THROW_UNSUPPORTED_OPERATION, query)) { searchSourceBuilder.parseXContent(parser); } SearchRequestBuilder searchRequestBuilder = new SearchRequestBuilder(client, SearchAction.INSTANCE); return searchRequestBuilder.setIndices(indexName).setSource(searchSourceBuilder).execute().actionGet(); }
namedWriteableRegistry = new NamedWriteableRegistry(entries); xContentRegistry = new NamedXContentRegistry(Stream.of( searchModule.getNamedXContents().stream() ).flatMap(Function.identity()).collect(toList())); IndexScopedSettings indexScopedSettings = settingsModule.getIndexScopedSettings();
NetworkModule.getNamedXContents().stream(), indicesModule.getNamedXContents().stream(), searchModule.getNamedXContents().stream(), pluginsService.filterPlugins(Plugin.class).stream() .flatMap(p -> p.getNamedXContent().stream()),
this.xContentRegistry = new NamedXContentRegistry(Stream.of( NetworkModule.getNamedXContents().stream(), searchModule.getNamedXContents().stream(), pluginsService.filterPlugins(Plugin.class).stream() .flatMap(p -> p.getNamedXContent().stream()),