类 ElasticsearchBaseClient<T extends BaseT>

java.lang.Object
com.abasecode.opencode.es.ElasticsearchBaseClient<T>

@Component public class ElasticsearchBaseClient<T extends BaseT> extends Object
作者:
Jon e-mail: ijonso123@gmail.com url: Jon's blog url: project github url: AbaseCode.com
  • 字段详细资料

    • esConfig

      @Autowired private ElasticsearchConfig.EsConfig esConfig
    • SIMPLE_SCRIPT_ID

      private static final String SIMPLE_SCRIPT_ID
      另请参阅:
    • DEFAULT_SCRIPT_LANG

      private static final String DEFAULT_SCRIPT_LANG
      另请参阅:
    • PAGE_ONE

      private static final Integer PAGE_ONE
    • PAGE_SIZE

      private static final Integer PAGE_SIZE
    • client

      private co.elastic.clients.elasticsearch.ElasticsearchClient client
    • transport

      private co.elastic.clients.transport.rest_client.RestClientTransport transport
  • 构造器详细资料

    • ElasticsearchBaseClient

      @Autowired public ElasticsearchBaseClient(ElasticsearchConfig.EsConfig esConfig)
      Instantiation
    • ElasticsearchBaseClient

      public ElasticsearchBaseClient(co.elastic.clients.elasticsearch.ElasticsearchClient client, co.elastic.clients.transport.rest_client.RestClientTransport transport)
      Instantiation
      参数:
      client - ElasticsearchClient
      transport - RestClientTransport
  • 方法详细资料

    • hasIndexExist

      public boolean hasIndexExist(String index) throws IOException
      check if the index exists
      参数:
      index - index
      返回:
      boolean
      抛出:
      IOException
    • createIndex

      public boolean createIndex(String index, String indexJson) throws IOException
      create index by json
      参数:
      index -
      indexJson -
      返回:
      boolean
      抛出:
      IOException
    • createIndexByJsonFile

      public boolean createIndexByJsonFile(String index, String jsonPath) throws IOException
      create index by json file
      参数:
      index -
      jsonPath -
      返回:
      boolean
      抛出:
      IOException
    • deleteIndex

      public boolean deleteIndex(String index) throws IOException
      delete index
      参数:
      index -
      返回:
      boolean
      抛出:
      IOException
    • hasDocExist

      public boolean hasDocExist(String index, String id) throws IOException
      Check if the doc exists
      参数:
      index - index
      id - doc id
      返回:
      boolean
      抛出:
      IOException
    • deleteDoc

      public String deleteDoc(String index, String id) throws IOException
      delete doc by id
      参数:
      index - index
      id - doc id
      返回:
      string : deleted or not_found
      抛出:
      IOException
    • deleteBulkWithList

      public co.elastic.clients.elasticsearch.core.BulkResponse deleteBulkWithList(String index, List<String> ids) throws IOException
      delete doc by list
      参数:
      index - index
      ids - list
      返回:
      BulkResponse
      抛出:
      IOException
    • saveOrUpdateDocByJson

      public String saveOrUpdateDocByJson(String index, String json, String id, Boolean hasForce) throws IOException
      save or update doc
      参数:
      index - index
      json - json
      id - id
      hasForce - has force
      返回:
      String,updated or created
      抛出:
      IOException
    • saveOrUpdateDocByJson

      private String saveOrUpdateDocByJson(String index, String json, String id) throws IOException
      save or update doc
      参数:
      index - index
      json - json
      id - doc id
      返回:
      String,updated or created
      抛出:
      IOException
    • saveOrUpdateDocByJsonFile

      public String saveOrUpdateDocByJsonFile(String index, String file, String id, Boolean hasForce) throws IOException
      save or update doc by json file
      参数:
      index - index
      file - file
      id - doc id
      hasForce - has force
      返回:
      String,updated or created
      抛出:
      IOException
    • saveOrUpdateDocByJsonFile

      private String saveOrUpdateDocByJsonFile(String index, String file, String id) throws IOException
      save or update doc by json file
      参数:
      index - index
      file - file
      id - doc id
      返回:
      String,updated or created
      抛出:
      IOException
    • saveOrUpdateDoc

      public String saveOrUpdateDoc(String index, T t, boolean hasForce) throws IOException
      save or update by T
      参数:
      index - index
      t - T
      hasForce -
      返回:
      String,updated or created
      抛出:
      IOException
    • saveOrUpdateDoc

      private String saveOrUpdateDoc(String index, T t) throws IOException
      save or upate by T
      参数:
      index - index
      t - T
      返回:
      String,updated or created
      抛出:
      IOException
    • saveOrUpdateDocBulkWithJsonFiles

      public co.elastic.clients.elasticsearch.core.BulkResponse saveOrUpdateDocBulkWithJsonFiles(String index, String path) throws IOException
      save or update doc by bulk mode Note: json needs to be configured with id
      参数:
      index - index
      path - path
      返回:
      BulkResponse
      抛出:
      IOException
    • saveOrUpdateDocBulkWithJson

      public co.elastic.clients.elasticsearch.core.BulkResponse saveOrUpdateDocBulkWithJson(String index, List<String> jsons) throws IOException
      save or update doc by list
      参数:
      index - index
      jsons - json list
      返回:
      BulkResponse
      抛出:
      IOException
    • saveOrUpdateDocBulkWithList

      public co.elastic.clients.elasticsearch.core.BulkResponse saveOrUpdateDocBulkWithList(String index, List<T> list) throws IOException
      save or update doc by List
      参数:
      index - index
      list - lsit T
      返回:
      BulkResponse
      抛出:
      IOException
    • getSearchResponse

      private co.elastic.clients.elasticsearch.core.SearchResponse<Void> getSearchResponse(String index, String json, org.springframework.data.domain.PageRequest pageRequest) throws IOException
      get searchResponse
      参数:
      index - index
      json - json
      返回:
      SearchResponse
      抛出:
      IOException
    • getSearchResponse

      public co.elastic.clients.elasticsearch.core.SearchResponse<T> getSearchResponse(String index, String json, org.springframework.data.domain.PageRequest pageRequest, Class<T> clazz) throws IOException
      get searchResponse by json
      参数:
      index - index
      json - json
      pageRequest - pageRequest, nullable
      clazz - class
      返回:
      SearchResponse
      抛出:
      IOException
    • getSearchRequest

      public co.elastic.clients.elasticsearch.core.SearchRequest getSearchRequest(String index, String json, org.springframework.data.domain.PageRequest pageRequest)
      get searchRequest by json
      参数:
      index - index
      json - json
      pageRequest - pageRequest, nullable
      返回:
      SearchRequest
    • queryById

      public T queryById(String index, String id, Class<T> clazz) throws IOException
      query by id
      参数:
      index - index
      id - id
      clazz - class
      返回:
      T
      抛出:
      IOException
    • queryByKeywordSimple

      public List<T> queryByKeywordSimple(String index, String field, String keyword, Class<T> clazz) throws IOException
      query by keyword simple match
      参数:
      index - index
      field - field
      keyword - keyword
      clazz - class
      返回:
      List
      抛出:
      IOException
    • queryByJson

      public List<T> queryByJson(String index, String json, Class<T> clazz) throws IOException
      query by json
      参数:
      index - index
      json - json
      clazz - class
      返回:
      List
      抛出:
      IOException
    • queryFieldsByJson

      public List<Map<String,co.elastic.clients.json.JsonData>> queryFieldsByJson(String index, String json) throws IOException
      query fields by json. notice: Json must specify the fields to be returned
      参数:
      index - index
      json - json
      返回:
      List<Map<String, JsonData>>
      抛出:
      IOException
    • queryByJsonWithPage

      public org.springframework.data.domain.Page<T> queryByJsonWithPage(String index, String json, org.springframework.data.domain.PageRequest pageRequest, Class<T> clazz) throws IOException
      query by json with page
      参数:
      index - index
      json - json
      pageRequest - pageRequest
      clazz - class
      返回:
      Page
      抛出:
      IOException
    • queryByJsonWithPage

      public org.springframework.data.domain.Page<T> queryByJsonWithPage(String index, String json, Integer pageNum, Integer pageSize, Class<T> clazz) throws IOException
      query by json with page
      参数:
      index - index
      json - json
      pageNum - pageNum
      pageSize - pageSize
      clazz - class
      返回:
      Page
      抛出:
      IOException
    • queryFieldsByJsonWithPage

      public org.springframework.data.domain.Page<Map<String,co.elastic.clients.json.JsonData>> queryFieldsByJsonWithPage(String index, String json, org.springframework.data.domain.PageRequest pageRequest) throws IOException
      query fields by json with page notice: Json must specify the fields to be returned
      参数:
      index - index
      json - json
      pageRequest - pageRequest
      返回:
      Page
      抛出:
      IOException
    • queryFieldsByJsonWithPage

      public org.springframework.data.domain.Page<Map<String,co.elastic.clients.json.JsonData>> queryFieldsByJsonWithPage(String index, String json, Integer pageNum, Integer pageSize) throws IOException
      query by json with page notice: Json must specify the fields to be returned
      参数:
      index - index
      json - json
      pageNum - pageNum
      pageSize - pageSize
      返回:
      Page
      抛出:
      IOException
    • getStringTermsBucketByJson

      public List<co.elastic.clients.elasticsearch._types.aggregations.StringTermsBucket> getStringTermsBucketByJson(String index, String aggregationJson, String aggName) throws IOException
      get stringTermsBucket by json
      参数:
      index - index
      aggregationJson - json
      aggName - agg name
      返回:
      set
      抛出:
      IOException
    • getSuggestionsByJson

      public Set<String> getSuggestionsByJson(String index, String suggestionJson, String suggestName) throws IOException
      get suggestion sets by json
      参数:
      index - index
      suggestionJson - suggestion json
      suggestName - suggest name
      返回:
      Set
      抛出:
      IOException
    • getHistogramBucketByJson

      public List<co.elastic.clients.elasticsearch._types.aggregations.HistogramBucket> getHistogramBucketByJson(String index, String aggregationJson, String aggName) throws IOException
      get histogramBucket by json
      参数:
      index - index
      aggregationJson - aggregationJson
      aggName - agg name
      返回:
      List
      抛出:
      IOException
    • createQueryScript

      public void createQueryScript(String scriptId, String scriptSource, String language, boolean force) throws IOException
      create script
      参数:
      scriptId - script id
      scriptSource - script source, Content of source
      language - script language
      force - has force
      抛出:
      IOException
    • createQueryScript

      private void createQueryScript(String scriptId, String scriptSource, String language) throws IOException
      create script
      参数:
      scriptId - script id
      scriptSource - script template
      language - language
      抛出:
      IOException
    • createSimpleScriptTemplate

      private void createSimpleScriptTemplate() throws IOException
      create simple script template
      抛出:
      IOException
    • hasScriptExist

      public boolean hasScriptExist(String scriptId) throws IOException
      check script exist
      参数:
      scriptId - scriptId
      返回:
      boolean
      抛出:
      IOException
    • deleteScriptById

      public boolean deleteScriptById(String scriptId) throws IOException
      delete script template
      参数:
      scriptId -
      返回:
      boolean
      抛出:
      IOException
    • queryBySimpleTemplate

      public List<T> queryBySimpleTemplate(String index, String field, String value, Class<T> clazz) throws IOException
      query by simple script template

      DSL example: GET /product/_search/template { "id":"es-simple-script", "params": { "field":"title", "value":"大米" } }

      参数:
      index - index
      field - field
      value - value
      clazz - class
      返回:
      list
      抛出:
      IOException
    • queryByScriptTemplate

      public List<T> queryByScriptTemplate(Function<co.elastic.clients.elasticsearch.core.SearchTemplateRequest.Builder,co.elastic.clients.util.ObjectBuilder<co.elastic.clients.elasticsearch.core.SearchTemplateRequest>> fn, Class<T> clazz) throws IOException
      query by script template
      参数:
      fn - fn
      clazz - class
      返回:
      list
      抛出:
      IOException
    • queryByScriptTemplate

      public List<T> queryByScriptTemplate(String index, String scriptId, Map<String,co.elastic.clients.json.JsonData> map, Class<T> clazz) throws IOException
      query by script template
      参数:
      index - index
      scriptId - scriptId
      map - map
      clazz - class
      返回:
      List
      抛出:
      IOException
    • updateByQueryWithJson

      public Long updateByQueryWithJson(String index, String json) throws IOException
      update by query with json

      DSL example first: create script PUT /_scripts/price_add { "script":{ "lang": "painless", "source": "ctx._source.price += params.value" } } and then: POST /product/_update_by_query { "query": { "match_all": {} }, "script": { "id": "price_add", "params": { "value": 5 } } } all price will be increased by 5 java code reference test

      参数:
      index - index
      json - json
      返回:
      Long
      抛出:
      IOException
    • updateByQuery

      private co.elastic.clients.elasticsearch.core.UpdateByQueryResponse updateByQuery(String index, String json) throws IOException
      get UpdateByQueryResponse
      参数:
      index - index
      json - json
      返回:
      UpdateByQueryResponse
      抛出:
      IOException