使用 elasticsearch-rest-plus

优质
小牛编辑
128浏览
2023-12-01

1.bean注入方式

@Autowired
private ElasticsearchTemplate elasticsearchTemplate;

elasticsearchTemplate 方法如下:

/**
* Create an index for given indexName
*/
public boolean createIndex(String indexName)


/**
* Create an index for a class
* clazz is  an initialization  class  object and has an annotated @Document!
*/
public <T> boolean createIndex(Class<T> clazz)

/**
* Delete an index by its name
*/
public <T> boolean deleteIndex(String... indexNames)


/**
* Delete the index by class
* clazz is  an initialization  class  object and has an annotated @Document!
*/
public <T> boolean deleteIndex(Class<T> clazz) 

/**
* The Objects create indexes and Settings by default for putMapping
* clazz is  an initialization  class  object and has an annotated @Document!
*/
public <T> boolean putMapping(Class<T> clazz)


/**
*  No index  will be created for putMapping
*  mapping  any String or Map or XContentBuilder
*/
public <T> boolean putMapping(String indexName, String type,Object mapping)

/**
* @since 1.0.0 Default putMapping and refresh index for save
* entity is  an initialization  instance  object and has an annotated @Document!
*/
public <T> T save(T entity) 

/**
* @since 1.0.0 Default putMapping and refresh index for save
entities is  an initialization  instance  object and has an annotated @Document!
*/
public <T> int save(List<T> entities)

/**
*  the one object with provided id
* entity is  an initialization  instance  object and has an annotated @Document!
*/
public <T> T get(T entity) 

/**
*  the one object with provided id
*  clazz is  an initialization  class  object and has an annotated @Document!
*/
public <T> T get(Serializable id,Class<T> clazz) 





/**
* @since 1.0.0 Default refresh index for delete,
*  entity is  an initialization  instance  object and has an annotated @Document!
*/
public <T> int delete(T entity) 

/**
* @since 1.0.0 Default refresh index for delete,
* clazz is  an initialization  class  object and has an annotated @Document!
*/
public <T> int delete(Class<T> entity,Serializable id) 

/**
* Delete the one object with provided id
*/
public  int delete(String indexName, String type, Serializable id)

/**
* Delete the one object with provided id
*/
public  int delete(DeleteQuery deleteQuery)

/**
* @since 1.0.0 Default refresh index for delete,
*  clazz is  an initialization  class  object and has an annotated @Document!
*/
public <T> int deleteByIds(Class<T> entity,Iterable<?> ids) 

/**
*  check if id is exists for given id
*  clazz is  an initialization  class  object and has an annotated @Document!
*/
public <T> boolean exists(Class<T> clazz,Serializable id) 

/**
* @since 1.0.0 Default refresh index for update of the document,
* entity is  an initialization  instance  object and has an annotated @Document!
*/
public <T> T update(T entity)

/**
* @since 1.0.0 Default refresh index for update of the document,
* entities is  an initialization  instance  object and has an annotated @Document!
*/
public <T> int update(List<? extends T> entities)


/**
* @since 1.0.0 Default refresh index for update of the document,
* entity is  an initialization  instance  object and has an annotated @Document!
*/
public <T> T update(Serializable id, T entity)

/**
* Partial update of the document
*/
public <T> UpdateResponseMapper update(UpdateQuery query)

/**
* Bulk index all objects. Will do save or update
*/
public int bulkUpdate(List<UpdateQuery> queries) 


/**
* Create an index for given Settings
*/
public boolean createIndexSettings(IndexSettings settings)

/**
* create  settings using the create Indices Settings
*  settings  any String or Map or XContentBuilder
*/
public boolean createSettings(String indexName, Object settings)


/**
* refresh the index
*/

public void refresh(String indexName) 
/**
* refresh the index
*clazz is  an initialization class object and has an annotated @Document!
*/
public <T> boolean refresh(Class<T> clazz) 
/**
*  check if index is exists
*
*/
public <T> boolean indexExist(String indexName) 

/**
*  check if index is exists
*clazz is  an initialization class object and has an annotated @Document!
*/
public <T> boolean indexExist(Class<T> clazz) 

/**
* there is No  create index,
* putMapping and refresh index save for document
*/
public  <T> String document(DocumentQuery query) 

/**
* there is No  create index, putMapping and refresh index save for document
*/
public  <T> int bulkDocument(List<DocumentQuery> queries)
/**
* adding new alias
*
*/
public  <T> Boolean addAlias(String indexName,String alias) 

/**
* removing previously created alias
*/
public  <T> Boolean deleteAlias( String indexName,String alias)
/**
* check if alias is exists
*
*/
public  <T> Boolean existsAlias( String indexName,String alias) 

/**
* Execute the Object against elasticsearch and return ids
* clazz is  an initialization class object and has an annotated @Document!
*/
public <T> List<T> findByIds(Class<T> clazz,List<?> ids) 


/**
* Execute the Object against elasticsearch and return Object
* clazz is  an initialization class object and has an annotated @Document!
*/
public <T> List<T> findAll(Class<T> clazz) 

/**
* Execute the Object against  and Sort elasticsearch and return Object
* clazz is  an initialization class object and has an annotated @Document!
*/
public <T> List<T> findAll(Class<T> clazz, Sort sort) 
/**
* Execute the Object against  and page elasticsearch and return Page
* clazz is  an initialization class object and has an annotated @Document!
*/
public <T> Page<T> findByPage(Class<T> clazz,Page page) 

/**
* Execute the Object against  and page,Sort elasticsearch and return Page
* clazz is  an initialization class object and has an annotated @Document!
*/
public <T> Page<T> findByPage(Class<T> clazz,Page page,Sort sort)

/**
* Execute the query against elasticsearch and return the first returned object
* clazz is  an initialization class object and has an annotated @Document!
*/
public <T> T get(QueryCriteria queryCriteria, Class<?> clazz) 


/**
* Execute the Object against  and queryCriteria elasticsearch and return List
* clazz is  an initialization class object and has an annotated @Document!
*/
public <T> List<T> find(QueryCriteria queryCriteria, Class<?> clazz) 

/**
* Execute the Object against  and queryCriteria elasticsearch and return Page
* clazz is  an initialization class object and has an annotated @Document!
*/
public <T> Page<T> findByPage(QueryCriteria queryCriteria, Class<?> clazz) 
/**
*  number of elements found by Object
*  clazz is  an initialization class object and has an annotated @Document!
*/
public <T> long count(Class<T> clazz) 

/**
*  number of elements found by queryCriteria
* clazz is  an initialization class object and has an annotated @Document!
*/
public <T> long count(QueryCriteria queryCriteria, Class<T> clazz)



/**
* This method Aggregate query  must have aggregation or carry statBy
*/
public <T> List<Map<String, Object>> aggregate(QueryCriteria queryCriteria)

/**
* This method Aggregate query  must have aggregation
* clazz is  an initialization class object and has an annotated @Document!
*/
public <T> List<T> aggregate(QueryCriteria queryCriteria, Class<?> clazz) 

/**
* Query through queryCriteria condition and Aggregation must not be empty
*/
public <T> Page<Map<String, Object>> aggregateForPage(QueryCriteria queryCriteria) 
/**
* Query through queryCriteria condition and Aggregation must not be empty
* clazz is  an initialization class object and has an annotated @Document!
*/
public <T> Page<T> aggregateForPage(QueryCriteria queryCriteria,Class<?> clazz) 


/**
* open index
*/
public  <T> boolean open(String indexName)

public  <T> boolean open(Class<T> clazz) 
/**
* close index
*/
public  <T> boolean close( String indexName)
/**
* close index
*/
public  <T> boolean close(Class<T> clazz)

/**
* flush
*/
public  <T> boolean flush( String indexName) 
/**
* flush
*/
public  <T> boolean flush(Class<T> clazz) 


/**
* clearCache
*/
public  <T> boolean clearCache( String indexName) 

/**
* clearCache
*/
public  <T> boolean clearCache(Class<T> clazz)