org.springframework.data.elasticsearch.core.ElasticsearchTemplate Java Examples
The following examples show how to use
org.springframework.data.elasticsearch.core.ElasticsearchTemplate.
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: ElasticsearchTransactionRepository.java From servicecomb-pack with Apache License 2.0 | 5 votes |
public ElasticsearchTransactionRepository( ElasticsearchTemplate template, MetricsService metricsService, int batchSize, int refreshTime) { this.template = template; this.metricsService = metricsService; this.batchSize = batchSize; this.refreshTime = refreshTime; if (this.refreshTime > 0) { new Thread(new RefreshTimer(), "elasticsearch-repository-refresh").start(); } if (!this.template.indexExists(INDEX_NAME)) { this.template.createIndex(INDEX_NAME); } }
Example #2
Source File: BeihuMutilElasticsearchAutoConfiguration.java From beihu-boot with Apache License 2.0 | 5 votes |
public ElasticsearchTemplate elasticsearchTemplate(Client client) { try { SimpleElasticsearchMappingContext simpleElasticsearchMappingContext = new SimpleElasticsearchMappingContext(); ElasticsearchConverter elasticsearchConverter = new MappingElasticsearchConverter(simpleElasticsearchMappingContext); return new ElasticsearchTemplate(client, elasticsearchConverter); } catch (Exception var4) { throw new IllegalStateException(var4); } }
Example #3
Source File: FsmAutoConfiguration.java From servicecomb-pack with Apache License 2.0 | 5 votes |
@Bean @ConditionalOnProperty(value = "alpha.feature.akka.transaction.repository.type", havingValue = "elasticsearch") public TransactionRepository transactionRepository(MetricsService metricsService, ElasticsearchTemplate template) { return new ElasticsearchTransactionRepository(template, metricsService, repositoryElasticsearchBatchSize, repositoryElasticsearchRefreshTime); }
Example #4
Source File: FileSystemCrawler.java From klask-io with GNU General Public License v3.0 | 5 votes |
public FileSystemCrawler(String root, KlaskProperties klaskProperties, FileSearchRepository fileSearchRepository, ElasticsearchTemplate elasticsearchTemplate){ super(); this.root = root; this.rootPath = new java.io.File(this.root).toPath(); this.result = null; this.klaskProperties = klaskProperties; this.fileSearchRepository = fileSearchRepository; this.elasticsearchTemplate = elasticsearchTemplate; }
Example #5
Source File: SimpleSearchQueryBuilder.java From onetwo with Apache License 2.0 | 5 votes |
public QueryResult(ElasticsearchTemplate elasticsearchTemplate, SimpleSearchQueryBuilder queryBuilder, SearchResponse response) { super(); this.queryBuilder = queryBuilder; this.searchResponse = response; this.aggregationsResult = new AggregationsResult(this.searchResponse.getAggregations()); this.mapper = new DefaultResultMapper(elasticsearchTemplate.getElasticsearchConverter().getMappingContext()); }
Example #6
Source File: SimpleSearchQueryBuilder.java From onetwo with Apache License 2.0 | 5 votes |
public Aggregations queryAggs(ElasticsearchTemplate elasticsearchTemplate){ return doQuery(elasticsearchTemplate, response->{ /*Terms agg = response.getAggregations().get("hots"); List<Bucket> buckets = agg.getBuckets(); Object key = buckets.get(0).getKey(); Object doc = buckets.get(0).getDocCount();*/ return response.getAggregations(); }); }
Example #7
Source File: ElasticsearchSpringFactory.java From database-transform-tool with Apache License 2.0 | 5 votes |
/** * 描述: Elasticsearch服务初始化 * 时间: 2017年11月14日 上午10:55:02 * @author yi.zhang */ public void init(String clusterName,String servers,String username,String password){ try { TransportClientFactoryBean client = new TransportClientFactoryBean(); client.setClusterName(clusterName); String clusterNodes = ""; for(String server : servers.split(",")){ String[] address = server.split(":"); String ip = address[0]; int port=9300; if(address.length>1){ port = Integer.valueOf(address[1]); } if(StringUtil.isEmpty(clusterNodes)){ clusterNodes = ip+":"+port; }else{ clusterNodes +=","+ ip+":"+port; } } client.setClusterNodes(clusterNodes); if(!StringUtil.isEmpty(username)&&!StringUtil.isEmpty(password)){ Properties properties = new Properties(); properties.put("xpack.security.user",username+":"+password); client.setProperties(properties); } client.afterPropertiesSet(); template = new ElasticsearchTemplate(client.getObject()); } catch (Exception e) { logger.error("-----Elasticsearch Config init Error-----", e); } }
Example #8
Source File: SimpleSuggestionBuilder.java From onetwo with Apache License 2.0 | 5 votes |
@SuppressWarnings("unchecked") public List<? extends Option> getOptions(ElasticsearchTemplate elasticsearchTemplate){ if(StringUtils.isBlank(text)){ return Collections.emptyList(); } return get(elasticsearchTemplate, response->{ Suggestion<?> suggestion = response.getSuggest().getSuggestion(name); if(suggestion==null || suggestion.getEntries().isEmpty()){ return Collections.emptyList(); } Suggestion.Entry<? extends Option> entry = suggestion.getEntries().get(0); List<? extends Option> options = entry.getOptions(); return options; }); }
Example #9
Source File: SimpleSuggestionBuilder.java From onetwo with Apache License 2.0 | 5 votes |
public <R> R get(ElasticsearchTemplate elasticsearchTemplate, Function<SuggestResponse, R> mapper){ Assert.notNull(this.suggestion); Assert.notEmpty(indices); SuggestResponse response = elasticsearchTemplate.suggest(suggestion, this.indices.toArray(new String[0])); return mapper.apply(response); }
Example #10
Source File: DataElasticsearchApplication.java From building-microservices with Apache License 2.0 | 5 votes |
@Bean public CommandLineRunner example(CarRepository repository, ElasticsearchTemplate template) { return (args) -> { System.err.println("From the repository..."); repository.findByMakeIgnoringCase("fOrD").forEach(System.err::println); System.err.println("\nFrom the template..."); SearchQuery query = new NativeSearchQueryBuilder() .withQuery(fuzzyQuery("make", "Ronda")).build(); template.queryForList(query, Car.class).forEach(System.err::println); }; }
Example #11
Source File: SimpleSuggestionBuilder.java From onetwo with Apache License 2.0 | 4 votes |
public List<String> getTexts(ElasticsearchTemplate elasticsearchTemplate){ return getOptions(elasticsearchTemplate).stream() .map(opt->opt.getText().string()) .collect(Collectors.toList()); }
Example #12
Source File: ElasticSearchConfiguration.java From klask-io with GNU General Public License v3.0 | 4 votes |
@Bean public ElasticsearchTemplate elasticsearchTemplate(Client client, Jackson2ObjectMapperBuilder jackson2ObjectMapperBuilder) { return new ElasticsearchTemplate(client, new CustomEntityMapper(jackson2ObjectMapperBuilder.createXmlMapper(false).build())); }
Example #13
Source File: _ElasticSearchConfiguration.java From jhipster-ribbon-hystrix with GNU General Public License v3.0 | 4 votes |
@Bean public ElasticsearchTemplate elasticsearchTemplate(Client client, Jackson2ObjectMapperBuilder jackson2ObjectMapperBuilder) { return new ElasticsearchTemplate(client, new CustomEntityMapper(jackson2ObjectMapperBuilder.createXmlMapper(false).build())); }
Example #14
Source File: BuscadorConteudo.java From portal-de-servicos with MIT License | 4 votes |
@Autowired BuscadorConteudo(ElasticsearchTemplate et) { this.et = et; }
Example #15
Source File: PortalDeServicosIndex.java From portal-de-servicos with MIT License | 4 votes |
@Autowired public PortalDeServicosIndex(ElasticsearchTemplate es) { this.es = es; }
Example #16
Source File: PortalDeServicosIndexHealthIndicator.java From portal-de-servicos with MIT License | 4 votes |
@Autowired public PortalDeServicosIndexHealthIndicator(ElasticsearchTemplate es) { this.es = es; }
Example #17
Source File: SetupPortalElasticSearch.java From portal-de-servicos with MIT License | 4 votes |
@Autowired public SetupPortalElasticSearch(ElasticsearchTemplate es, PortalDeServicosIndex portalIndex) { this.es = es; this.portalIndex = portalIndex; }
Example #18
Source File: ESIndexer.java From oneops with Apache License 2.0 | 4 votes |
public void setTemplate(ElasticsearchTemplate template) { this.template = template; }
Example #19
Source File: SimpleSearchQueryBuilder.java From onetwo with Apache License 2.0 | 4 votes |
public <T> Page<T> queryForPage(ElasticsearchTemplate elasticsearchTemplate, Class<T> clazz){ NativeSearchQuery searchQuery = build(true); Page<T> page = elasticsearchTemplate.queryForPage(searchQuery, clazz); return page; }
Example #20
Source File: SimpleSearchQueryBuilder.java From onetwo with Apache License 2.0 | 4 votes |
public <T> List<T> queryForList(ElasticsearchTemplate elasticsearchTemplate, Class<T> clazz){ NativeSearchQuery searchQuery = build(true); List<T> page = elasticsearchTemplate.queryForList(searchQuery, clazz); return page; }
Example #21
Source File: SimpleSearchQueryBuilder.java From onetwo with Apache License 2.0 | 4 votes |
public QueryResult doQueryResult(ElasticsearchTemplate elasticsearchTemplate){ return doQuery(elasticsearchTemplate, response->{ return new QueryResult(elasticsearchTemplate, this, response); }); }
Example #22
Source File: SimpleSearchQueryBuilder.java From onetwo with Apache License 2.0 | 4 votes |
public <R> R doQuery(ElasticsearchTemplate elasticsearchTemplate, ResultsExtractor<R> resultsExtractor){ NativeSearchQuery searchQuery = build(true); return elasticsearchTemplate.query(searchQuery, resultsExtractor); }
Example #23
Source File: SimpleSearchQueryBuilder.java From onetwo with Apache License 2.0 | 4 votes |
public SuggestResponse querySuggest(ElasticsearchTemplate elasticsearchTemplate, SuggestionBuilder<?> suggestion){ SuggestResponse reponse = elasticsearchTemplate.suggest(suggestion, this.indices.toArray(new String[0])); return reponse; }
Example #24
Source File: ElasticsearchConfiguration.java From expper with GNU General Public License v3.0 | 4 votes |
@Bean public ElasticsearchTemplate elasticsearchTemplate(Client client, Jackson2ObjectMapperBuilder jackson2ObjectMapperBuilder) { return new ElasticsearchTemplate(client, new CustomEntityMapper(jackson2ObjectMapperBuilder.createXmlMapper(false).build())); }
Example #25
Source File: ApplicationConfiguration.java From spring-data-examples with Apache License 2.0 | 4 votes |
@Bean public ElasticsearchTemplate elasticsearchTemplate(Client client) { return new ElasticsearchTemplate(client); }
Example #26
Source File: ElasticSearchConfig.java From spring4-sandbox with Apache License 2.0 | 4 votes |
@Bean public ElasticsearchOperations elasticsearchTemplate() { return new ElasticsearchTemplate(NodeBuilder.nodeBuilder().local(true).node().client()); }
Example #27
Source File: ElasticSearchConfig.java From spring4-sandbox with Apache License 2.0 | 4 votes |
@Bean public ElasticsearchOperations elasticsearchTemplate() { return new ElasticsearchTemplate(NodeBuilder.nodeBuilder().local(true).node() .client()); }
Example #28
Source File: UKDataContext.java From youkefu with Apache License 2.0 | 4 votes |
public static ElasticsearchTemplate getTemplet() { return templet; }
Example #29
Source File: QcTask.java From youkefu with Apache License 2.0 | 4 votes |
@Autowired public void setElasticsearchTemplate(ElasticsearchTemplate elasticsearchTemplate) { this.elasticsearchTemplate = elasticsearchTemplate; }
Example #30
Source File: EkmKnowledgeTimesRepositoryImpl.java From youkefu with Apache License 2.0 | 4 votes |
@Autowired public void setElasticsearchTemplate(ElasticsearchTemplate elasticsearchTemplate) { this.elasticsearchTemplate = elasticsearchTemplate; }