Uploaded image for project: 'PUBLIC - Liferay Documentation'
  1. PUBLIC - Liferay Documentation
  2. LRDOCS-7653

Creating Application-Driven Indexes

    Details

      Description

      We must instruct third party devs how to, and how not to, programmatically create application-specific indexes.

      1. Imports:
        import com.liferay.portal.search.engine.adapter.document.IndexDocumentRequest;
        import com.liferay.portal.search.engine.adapter.index.CreateIndexRequest;
        import com.liferay.portal.search.index.IndexNameBuilder;
        
      2. Inject:
        
        	@Reference
        	protected IndexNameBuilder indexNameBuilder;
        
        	@Reference(
        		cardinality = ReferenceCardinality.OPTIONAL,
        		policy = ReferencePolicy.DYNAMIC,
        		policyOption = ReferencePolicyOption.GREEDY,
        		target = "(search.engine.impl=Elasticsearch)"
        	)
        	protected volatile SearchEngineAdapter searchEngineAdapter;
        
      3. Use (build index name):
        protected String getIndexName(long companyId) {
            return indexNameBuilder.getIndexName(companyId) + "-my-index-name";
        }
        
      4. Create index:
        		CreateIndexRequest createIndexRequest = new CreateIndexRequest(
        			getIndexName(companyId));
        
        //            set settings and mappings on the request
        //            createIndexRequest.setSource(...);
        
                      searchEngineAdapter.execute(createIndexRequest);
        
      5. Index document:
        
        //             Build Document
        
        		IndexDocumentRequest indexDocumentRequest = new IndexDocumentRequest(
        			getIndexName(companyId), document);
        
                       searchEngineAdapter.execute(indexDocumentRequest);
        

      See also LPS-117702.

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              russell.bohl Russell Bohl
              Reporter:
              russell.bohl Russell Bohl
              Subject Matter Expert:
              Tibor Lipusz
              Participants of an Issue:
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

                Dates

                Created:
                Updated:

                  Zendesk Support

                    Packages

                    Version Package
                    7.2.x
                    7.3.x