Class OpenSearchServiceImpl

java.lang.Object
org.craftercms.search.opensearch.impl.OpenSearchServiceImpl
All Implemented Interfaces:
AutoCloseable, OpenSearchService
Direct Known Subclasses:
MultiOpenSearchServiceImpl

public class OpenSearchServiceImpl extends Object implements OpenSearchService
Default implementation of OpenSearchService
Author:
joseross
  • Field Details

    • DEFAULT_LOCAL_ID_NAME

      public static final String DEFAULT_LOCAL_ID_NAME
      See Also:
    • DEFAULT_SCROLL_SIZE

      public static final int DEFAULT_SCROLL_SIZE
      See Also:
    • DEFAULT_SCROLL_TIMEOUT

      public static final String DEFAULT_SCROLL_TIMEOUT
      See Also:
    • documentBuilder

      protected final OpenSearchDocumentBuilder documentBuilder
      Document Builder
    • documentParser

      protected final DocumentParser documentParser
      Document Parser
    • openSearchClient

      protected final org.opensearch.client.opensearch.OpenSearchClient openSearchClient
      The OpenSearch client
    • localIdFieldName

      protected String localIdFieldName
      The name of the field for full ids
    • scrollSize

      protected int scrollSize
      The number of results to return for each scroll request
    • scrollTimeout

      protected String scrollTimeout
      The timeout for each the scroll request
  • Constructor Details

  • Method Details

    • setLocalIdFieldName

      public void setLocalIdFieldName(String localIdFieldName)
    • setScrollSize

      public void setScrollSize(int scrollSize)
    • setScrollTimeout

      public void setScrollTimeout(String scrollTimeout)
    • searchField

      public List<String> searchField(String aliasName, String field, org.opensearch.client.opensearch._types.query_dsl.Query query) throws OpenSearchException
      Performs a search for a specific field
      Specified by:
      searchField in interface OpenSearchService
      Parameters:
      aliasName - the name of the index
      field - the name of the field
      query - the filters to apply
      Returns:
      the list of values that match the search
      Throws:
      OpenSearchException - if there is any error during the operation
    • searchId

      public Map<String,Object> searchId(String aliasName, String docId)
      Specified by:
      searchId in interface OpenSearchService
    • index

      public void index(String indexName, String siteName, String docId, Map<String,Object> doc)
      Specified by:
      index in interface OpenSearchService
    • doIndex

      protected void doIndex(org.opensearch.client.opensearch.OpenSearchClient client, String indexName, String siteName, String docId, Map<String,Object> doc)
      Performs the index operation using the given OpenSearch client
    • index

      public void index(String indexName, String siteName, String docId, String xml, Map<String,Object> additionalFields) throws OpenSearchException
      Performs an index for the given xml file
      Specified by:
      index in interface OpenSearchService
      Parameters:
      indexName - the name of the index
      siteName - the name of the site
      docId - the id of the document
      xml - the content of the document
      additionalFields - additional fields to index
      Throws:
      OpenSearchException - if there is any error during the operation
    • indexBinary

      public void indexBinary(String indexName, String siteName, String path, org.craftercms.core.service.Content content, Map<String,Object> additionalFields) throws OpenSearchException
      Performs an index for the given binary file
      Specified by:
      indexBinary in interface OpenSearchService
      Parameters:
      indexName - the name of the index
      siteName - the name of the site
      path - the path of the document
      content - the content of the document
      additionalFields - the additional fields to index
      Throws:
      OpenSearchException - if there is any error during the operation
    • indexBinary

      public void indexBinary(String indexName, String siteName, String path, org.springframework.core.io.Resource resource, Map<String,Object> additionalFields) throws OpenSearchException
      Specified by:
      indexBinary in interface OpenSearchService
      Throws:
      OpenSearchException
    • delete

      public void delete(String indexName, String siteName, String docId) throws OpenSearchException
      Performs a delete for the given document
      Specified by:
      delete in interface OpenSearchService
      Parameters:
      indexName - the name of the index
      siteName - the id of the site
      docId - the id of the document
      Throws:
      OpenSearchException - if there is any error during the operation
    • doDelete

      protected void doDelete(org.opensearch.client.opensearch.OpenSearchClient client, String indexName, String siteName, String docId)
      Performs the delete operation using the given OpenSearch client
    • refresh

      public void refresh(String indexName) throws OpenSearchException
      Performs a refresh for a given index
      Specified by:
      refresh in interface OpenSearchService
      Parameters:
      indexName - the name of the index
      Throws:
      OpenSearchException - if there is any error during the operation
    • doRefresh

      protected void doRefresh(org.opensearch.client.opensearch.OpenSearchClient client, String indexName) throws OpenSearchException
      Performs the refresh operation using the given OpenSearch client
      Throws:
      OpenSearchException
    • getId

      protected String getId(String path)
      Hashes the full path to use as a unique id for OpenSearch
      Parameters:
      path - the path of the file
      Returns:
      MD5 hash for the path
    • close

      public void close() throws Exception
      Specified by:
      close in interface AutoCloseable
      Throws:
      Exception