當前位置: 首頁>>代碼示例>>Java>>正文


Java ElasticsearchTemplate類代碼示例

本文整理匯總了Java中org.springframework.data.elasticsearch.core.ElasticsearchTemplate的典型用法代碼示例。如果您正苦於以下問題:Java ElasticsearchTemplate類的具體用法?Java ElasticsearchTemplate怎麽用?Java ElasticsearchTemplate使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


ElasticsearchTemplate類屬於org.springframework.data.elasticsearch.core包,在下文中一共展示了ElasticsearchTemplate類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: elasticsearchTemplate

import org.springframework.data.elasticsearch.core.ElasticsearchTemplate; //導入依賴的package包/類
@Bean
public ElasticsearchTemplate elasticsearchTemplate(Client client, ObjectMapper objectMapper) {
    EntityMapper mapper = new EntityMapper() {
        @Override
        public String mapToString(Object object) throws IOException {
            return objectMapper.writeValueAsString(object);
        }

        @Override
        public <T> T mapToObject(String source, Class<T> clazz) throws IOException {
            return objectMapper.readValue(source, clazz);
        }
    };

    return new ElasticsearchTemplate(client, mapper);
}
 
開發者ID:LIBCAS,項目名稱:ARCLib,代碼行數:17,代碼來源:ElasticsearchTemplateProducer.java

示例2: setElasticsearchTemplate

import org.springframework.data.elasticsearch.core.ElasticsearchTemplate; //導入依賴的package包/類
@Autowired
public void setElasticsearchTemplate(ElasticsearchTemplate elasticsearchTemplate) {
	this.elasticsearchTemplate = elasticsearchTemplate;
       if(!elasticsearchTemplate.indexExists("uckefu")){
       	elasticsearchTemplate.createIndex("uckefu") ;
       }
       if(!elasticsearchTemplate.typeExists("uckefu" , "uc_ask_topiccomment")){
       	elasticsearchTemplate.putMapping(TopicComment.class) ;
       }
   }
 
開發者ID:uckefu,項目名稱:uckefu,代碼行數:11,代碼來源:TopicCommentRepositoryImpl.java

示例3: setUp

import org.springframework.data.elasticsearch.core.ElasticsearchTemplate; //導入依賴的package包/類
@Before
public void setUp() throws Exception {
    /**
     * 如果es集群安裝了x-pack插件則以此種方式連接集群
     * 1. java客戶端的方式是以tcp協議在9300端口上進行通信
     * 2. http客戶端的方式是以http協議在9200端口上進行通信
     */
    Settings settings = Settings.builder(). put("xpack.security.user", "elastic:changeme").build();
    client = new PreBuiltXPackTransportClient(settings)
            .addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName("localhost"), 9300));
    elasticsearchTemplate = new ElasticsearchTemplate(client);
    final CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
    credentialsProvider.setCredentials(AuthScope.ANY,
            new UsernamePasswordCredentials("elastic", "changeme"));
    restClient = RestClient.builder(new HttpHost("localhost",9200,"http"))
            .setHttpClientConfigCallback(new RestClientBuilder.HttpClientConfigCallback() {
                @Override
                public HttpAsyncClientBuilder customizeHttpClient(HttpAsyncClientBuilder httpClientBuilder) {
                    return httpClientBuilder.setDefaultCredentialsProvider(credentialsProvider);
                }
            }).build();
}
 
開發者ID:felayman,項目名稱:elasticsearch-full,代碼行數:23,代碼來源:XPackBaseDemo.java

示例4: beforeClass

import org.springframework.data.elasticsearch.core.ElasticsearchTemplate; //導入依賴的package包/類
@BeforeClass
public static void beforeClass() throws Exception {
  elasticsearchServer = new EmbeddedElasticsearchServer();
  elasticsearchTemplate = new ElasticsearchTemplate(elasticsearchServer.getClient());

  elasticsearchTemplate.deleteIndex(INDEX_NAME);

  String mappings = StreamUtils.copyToString(
      ODataIntegrationTest.class.getResourceAsStream("mappings.json"),
      StandardCharsets.UTF_8);
  createIndex(INDEX_NAME, mappings);
  waitForGreenStatus(INDEX_NAME);

  indexDocument("entityId1", "entity1-source.json");
  indexDocument("entityId2", "entity2-source.json");
  indexDocument("entityId3", "entity3-source.json");

  refresh(INDEX_NAME);
}
 
開發者ID:pukkaone,項目名稱:odata-spring-boot-starter,代碼行數:20,代碼來源:ODataIntegrationTest.java

示例5: AnnotationSearchServiceImpl

import org.springframework.data.elasticsearch.core.ElasticsearchTemplate; //導入依賴的package包/類
@Autowired
   /**
    *
    * @param annotationUtils
    *            {@code AnnotationUtils} helper for annotations
    * @param template
    *            {@code ElasticsearchTemplate} what we use to get the
    *            elasticsearch client
    * @param textSearchService
    *            {@code TextSearchService} our text search service
    * @param cacheManager
    *            {@code CacheManager} our cache manager
    */
   public AnnotationSearchServiceImpl(AnnotationUtils annotationUtils, ElasticsearchTemplate template,
    TextSearchService textSearchService, CacheManager cacheManager) {
this.annotationUtils = annotationUtils;
this.client = template.getClient();
this.textSearchService = textSearchService;
this.cacheManager = cacheManager;
   }
 
開發者ID:dlcs,項目名稱:the-mathmos-server,代碼行數:21,代碼來源:AnnotationSearchServiceImpl.java

示例6: setUp

import org.springframework.data.elasticsearch.core.ElasticsearchTemplate; //導入依賴的package包/類
@Before
   public void setUp() throws Exception {
annotationUtils = new AnnotationUtils();
searchQueryUtils = new SearchQueryUtils();
template = mock(ElasticsearchTemplate.class);
client = mock(Client.class);
when(template.getClient()).thenReturn(client);
textSearchService = mock(TextSearchService.class);
mixedCache = mock(Cache.class);
cacheManager = mock(CacheManager.class);
when(cacheManager.getCache(anyString())).thenReturn(mixedCache);
when(mixedCache.get(queryString)).thenReturn(null);
Map map = new HashMap();
mixedCache.put(queryStringWithPage, map);
//when(mixedCache.get(queryStringWithPage)).thenReturn(new ValueWrapper())
impl = new W3CSearchServiceImpl(annotationUtils, template, textSearchService, cacheManager);
   }
 
開發者ID:dlcs,項目名稱:the-mathmos-server,代碼行數:18,代碼來源:W3CSearchServiceImpTest.java

示例7: setUp

import org.springframework.data.elasticsearch.core.ElasticsearchTemplate; //導入依賴的package包/類
@Before
   public void setUp() throws Exception {
annotationUtils = new AnnotationUtils();
searchQueryUtils = new SearchQueryUtils();
template = mock(ElasticsearchTemplate.class);
client = mock(Client.class);
when(template.getClient()).thenReturn(client);
textSearchService = mock(TextSearchService.class);
mixedCache = mock(Cache.class);
cacheManager = mock(CacheManager.class);
when(cacheManager.getCache(anyString())).thenReturn(mixedCache);
when(mixedCache.get(queryString)).thenReturn(null);
Map map = new HashMap();
mixedCache.put(queryStringWithPage, map);
//when(mixedCache.get(queryStringWithPage)).thenReturn(new ValueWrapper())
impl = new OASearchServiceImpl(annotationUtils, template, textSearchService, cacheManager);
   }
 
開發者ID:dlcs,項目名稱:the-mathmos-server,代碼行數:18,代碼來源:OASearchServiceImpTest.java

示例8: setUp

import org.springframework.data.elasticsearch.core.ElasticsearchTemplate; //導入依賴的package包/類
@Before
public void setUp() throws Exception {
    assetObjectRepo = Mockito.mock(AssetObjectRepo.class);
    elasticsearchTemplate = Mockito.mock(ElasticsearchTemplate.class);
    uuidGenerator = new SimpleUUIDGenerator();

    AssetObjectServiceImpl assetObjectService = new AssetObjectServiceImpl();
    ReflectionTestUtils.setField(assetObjectService, "assetObjectRepo", assetObjectRepo);
    ReflectionTestUtils.setField(assetObjectService, "uuidGenerator", uuidGenerator);
    ReflectionTestUtils.setField(assetObjectService, "elasticsearchTemplate", elasticsearchTemplate);

    final MccyAssetSettings settings = new MccyAssetSettings();
    storageDir = temporaryFolder.newFolder();
    settings.setStorageDir(storageDir);
    assetObjectService.setSettings(settings);

    this.assetObjectService = assetObjectService;
}
 
開發者ID:moorkop,項目名稱:mccy-engine,代碼行數:19,代碼來源:AssetObjectServiceImplTest.java

示例9: elasticsearchTemplate

import org.springframework.data.elasticsearch.core.ElasticsearchTemplate; //導入依賴的package包/類
@Bean
ElasticsearchOperations elasticsearchTemplate() throws IOException {

	// transport client
	Settings settings = ImmutableSettings.settingsBuilder()
	        .put("cluster.name", "elasticsearch")
	        .put("username","myname")
	        .put("password","mypassword").build();
	        
	 Client client = new TransportClient(settings)
        .addTransportAddress(new InetSocketTransportAddress("192.168.73.186", 9300));
	 
	 return new ElasticsearchTemplate(client);

	// node client
	//		return new ElasticsearchTemplate(nodeBuilder()
	//				.local(true)
	//				.settings(
	//						ImmutableSettings.settingsBuilder()
	//								.put("cluster.name", "elasticsearch")
	//								.put("username", "myname")
	//								.put("password", "mypassword").build()).node()
	//				.client());
}
 
開發者ID:phstudy,項目名稱:SpringMVC-SpringDataElasticsearch,代碼行數:25,代碼來源:ElasticsearchConfig.java

示例10: init

import org.springframework.data.elasticsearch.core.ElasticsearchTemplate; //導入依賴的package包/類
/**
 * 描述: 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);
	}
}
 
開發者ID:dev-share,項目名稱:css-elasticsearch,代碼行數:36,代碼來源:ElasticsearchSpringFactory.java

示例11: reindexSubset

import org.springframework.data.elasticsearch.core.ElasticsearchTemplate; //導入依賴的package包/類
/**
 * Reindexes only specified IndexedStores or all if not specified
 *
 * @param dropIndexes specify if indexes should be dropped prior to reindexing
 * @param storeClasses store classes subset to reindex or null if all
 */
@Transactional
public void reindexSubset(boolean dropIndexes, List<Class<? extends IndexedStore>> storeClasses) {
    if (dropIndexes) {
        stores.stream()
              .map(Utils::unwrap)
              .filter(store -> storeClasses == null || storeClasses.contains(store.getClass()))
              .map(IndexedStore::getIndexName)
              .distinct()
              .forEach(index -> {
                  if (template.indexExists(index)) {
                      log.info("Deleting index {}.", index);
                      template.deleteIndex(index);
                  }

                  log.info("Creating index {}.", index);
                  String settings = ElasticsearchTemplate.readFileFromClasspath("/es_settings.json");
                  template.createIndex(index, settings);
              });
    }

    stores.stream()
          .map(Utils::unwrap)
          .filter(store -> storeClasses == null || storeClasses.contains(store.getClass()))
          .forEach(store -> {
              log.info("Reindexing store {}", store.getClass().getName());
              store.reindex();
              log.info("Reindexing complete");
          });
}
 
開發者ID:LIBCAS,項目名稱:ARCLib,代碼行數:36,代碼來源:GlobalReindexer.java

示例12: setElasticsearchTemplate

import org.springframework.data.elasticsearch.core.ElasticsearchTemplate; //導入依賴的package包/類
@Autowired
public void setElasticsearchTemplate(ElasticsearchTemplate elasticsearchTemplate) {
	this.elasticsearchTemplate = elasticsearchTemplate;
       if(!elasticsearchTemplate.indexExists("uckefu")){
       	elasticsearchTemplate.createIndex("uckefu") ;
       }
       if(!elasticsearchTemplate.typeExists("uckefu" , "uc_ask_message")){
       	elasticsearchTemplate.putMapping(Message.class) ;
       }
   }
 
開發者ID:uckefu,項目名稱:uckefu,代碼行數:11,代碼來源:UKeFuRepositoryImpl.java

示例13: setElasticsearchTemplate

import org.springframework.data.elasticsearch.core.ElasticsearchTemplate; //導入依賴的package包/類
@Autowired
public void setElasticsearchTemplate(ElasticsearchTemplate elasticsearchTemplate) {
	this.elasticsearchTemplate = elasticsearchTemplate;
       if(!elasticsearchTemplate.indexExists("uckefu")){
       	elasticsearchTemplate.createIndex("uckefu") ;
       }
       if(!elasticsearchTemplate.typeExists("uckefu" , "uc_ask_topicview")){
       	elasticsearchTemplate.putMapping(TopicView.class) ;
       }
   }
 
開發者ID:uckefu,項目名稱:uckefu,代碼行數:11,代碼來源:TopicViewRepositoryImpl.java

示例14: setElasticsearchTemplate

import org.springframework.data.elasticsearch.core.ElasticsearchTemplate; //導入依賴的package包/類
@Autowired
public void setElasticsearchTemplate(ElasticsearchTemplate elasticsearchTemplate) {
       this.elasticsearchTemplate = elasticsearchTemplate;
       if(!elasticsearchTemplate.indexExists(Topic.class)){
       	elasticsearchTemplate.createIndex(Topic.class) ;
       }
       if(!elasticsearchTemplate.typeExists("uckefu" , "uc_ask_topic")){
       	elasticsearchTemplate.putMapping(Topic.class) ;
       }
   }
 
開發者ID:uckefu,項目名稱:uckefu,代碼行數:11,代碼來源:TopicRepositoryImpl.java

示例15: ElasticsearchIndexService

import org.springframework.data.elasticsearch.core.ElasticsearchTemplate; //導入依賴的package包/類
public ElasticsearchIndexService(
    UserRepository userRepository,
    UserSearchRepository userSearchRepository,
    ApplicationRepository applicationRepository,
    ApplicationSearchRepository applicationSearchRepository,
    CampagneRepository campagneRepository,
    CampagneSearchRepository campagneSearchRepository,
    ResultatRepository resultatRepository,
    ResultatSearchRepository resultatSearchRepository,
    TesteurRepository testeurRepository,
    TesteurSearchRepository testeurSearchRepository,
    TypeTestRepository typeTestRepository,
    TypeTestSearchRepository typeTestSearchRepository,
    ElasticsearchTemplate elasticsearchTemplate) {
    this.userRepository = userRepository;
    this.userSearchRepository = userSearchRepository;
    this.applicationRepository = applicationRepository;
    this.applicationSearchRepository = applicationSearchRepository;
    this.campagneRepository = campagneRepository;
    this.campagneSearchRepository = campagneSearchRepository;
    this.resultatRepository = resultatRepository;
    this.resultatSearchRepository = resultatSearchRepository;
    this.testeurRepository = testeurRepository;
    this.testeurSearchRepository = testeurSearchRepository;
    this.typeTestRepository = typeTestRepository;
    this.typeTestSearchRepository = typeTestSearchRepository;
    this.elasticsearchTemplate = elasticsearchTemplate;
}
 
開發者ID:pascalgrimaud,項目名稱:qualitoast,代碼行數:29,代碼來源:ElasticsearchIndexService.java


注:本文中的org.springframework.data.elasticsearch.core.ElasticsearchTemplate類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。