网站引导页下载,深圳培训网站建设,济宁一建建设集团有限公司,51网站空间相册在哪里如果需要屏蔽其他项目对Elasticsearch的直接访问操作#xff0c;统一由一个入口访问操作Elasticsearch#xff0c;可以考虑直接传入JSON格式语句解析执行。
相关依赖包
propertieselasticsearch.version7.9.3/elasticsearch.versionelasticsea…如果需要屏蔽其他项目对Elasticsearch的直接访问操作统一由一个入口访问操作Elasticsearch可以考虑直接传入JSON格式语句解析执行。
相关依赖包
propertieselasticsearch.version7.9.3/elasticsearch.versionelasticsearch.rest.version7.9.3/elasticsearch.rest.version
/properties!-- Elasticsearch依赖包--
dependencygroupIdorg.elasticsearch/groupIdartifactIdelasticsearch/artifactIdversion${elasticsearch.version}/version
/dependencydependencygroupIdorg.elasticsearch.client/groupIdartifactIdtransport/artifactIdversion${elasticsearch.version}/version
/dependencydependencygroupIdorg.elasticsearch.client/groupIdartifactIdelasticsearch-rest-client/artifactIdversion${elasticsearch.rest.version}/version
/dependencydependencygroupIdorg.elasticsearch.client/groupIdartifactIdelasticsearch-rest-high-level-client/artifactIdversion${elasticsearch.rest.version}/version
/dependency部分代码
protected static final NamedXContentRegistry namedXContentRegistry;static {SearchModule searchModule new SearchModule(Settings.builder().build(), false, new ArrayList());ListNamedXContentRegistry.Entry namedXContents searchModule.getNamedXContents();namedXContents.addAll(getDefaultNamedXContents());namedXContentRegistry new NamedXContentRegistry(namedXContents);}protected SearchResponse searchResponse(RestHighLevelClient restHighLevelClient, String statement,MapString, Object params, String... indices) {SearchResponse searchResponse null;SearchRequest searchRequest new SearchRequest(indices);SearchSourceBuilder searchSourceBuilder new SearchSourceBuilder();try {searchSourceBuilder.parseXContent(XContentType.JSON.xContent().createParser(namedXContentRegistry,DeprecationHandler.IGNORE_DEPRECATIONS, statement));searchRequest.source(searchSourceBuilder);Object scrollTimeoutObj params.get(SCROLL_TIMEOUT);if (null ! scrollTimeoutObj) {searchRequest.scroll(String.valueOf(scrollTimeoutObj));}long startTimeMillis System.currentTimeMillis();searchResponse restHighLevelClient.search(searchRequest, RequestOptions.DEFAULT);executionSqlLog(statement, startTimeMillis, indices);} catch (IOException e) {log.error(e.getMessage(), e);}return searchResponse;}protected SearchResponse scrollSearchResponse(RestHighLevelClient restHighLevelClient, String scrollId) {try {return restHighLevelClient.scroll(new SearchScrollRequest(scrollId), RequestOptions.DEFAULT);} catch (IOException e) {log.error(e.getMessage(), e);}return null;}protected CountResponse countResponse(RestHighLevelClient restHighLevelClient, String statement,MapString, Object params, String... indices) {CountResponse countResponse null;CountRequest countRequest new CountRequest(indices);SearchSourceBuilder searchSourceBuilder new SearchSourceBuilder();try {searchSourceBuilder.parseXContent(XContentType.JSON.xContent().createParser(namedXContentRegistry,DeprecationHandler.IGNORE_DEPRECATIONS, statement));countRequest.source(searchSourceBuilder);long startTimeMillis System.currentTimeMillis();countResponse restHighLevelClient.count(countRequest, RequestOptions.DEFAULT);executionSqlLog(statement, startTimeMillis, indices);} catch (IOException e) {log.error(e.getMessage(), e);}return countResponse;}private static ListNamedXContentRegistry.Entry getDefaultNamedXContents() {MapString, ContextParserObject, ? extends Aggregation map new HashMap();map.put(TopHitsAggregationBuilder.NAME, (p, c) - ParsedTopHits.fromXContent(p, (String) c));map.put(DateRangeAggregationBuilder.NAME, (p, c) - ParsedDateRange.fromXContent(p, (String) c));map.put(FilterAggregationBuilder.NAME, (p, c) - ParsedFilter.fromXContent(p, (String) c));map.put(SumAggregationBuilder.NAME, (p, c) - ParsedSum.fromXContent(p, (String) c));map.put(CardinalityAggregationBuilder.NAME, (p, c) - ParsedCardinality.fromXContent(p, (String) c));map.put(StringTerms.NAME, (p, c) - ParsedStringTerms.fromXContent(p, (String) c));map.put(LongTerms.NAME, (p, c) - ParsedLongTerms.fromXContent(p, (String) c));map.put(DoubleTerms.NAME, (p, c) - ParsedDoubleTerms.fromXContent(p, (String) c));return map.entrySet().stream().map(entry -new NamedXContentRegistry.Entry(Aggregation.class, new ParseField(entry.getKey()), entry.getValue())).collect(Collectors.toList());}private void executionSqlLog(String statement, long startTimeMillis, String... indices) {if (!esProperties.isExecutionSqlEnable()) {return;}long spendTime System.currentTimeMillis() - startTimeMillis;log.info(\n SQL START \nExecution INX {} [{} ms] \nExecution SQL {} \n SQL END \n, String.join(Constants.SYMBOL_COMMA, indices),spendTime, statement.replaceAll(\\s{2,}, ));}}