Search in sources :

Example 1 with IndexDocument

use of com.enonic.xp.repo.impl.elasticsearch.document.IndexDocument in project xp by enonic.

the class NodeStoreDocumentFactory method createDataDocument.

private IndexDocument createDataDocument() {
    final IndexConfigDocument indexConfigDocument = this.node.getIndexConfigDocument();
    final IndexDocument.Builder builder = IndexDocument.create().id(this.node.id().toString()).indexName(IndexNameResolver.resolveSearchIndexName(this.repositoryId)).indexTypeName(this.branch.getValue()).analyzer(indexConfigDocument.getAnalyzer()).indexItems(createIndexItems()).refreshAfterOperation(this.refresh);
    return builder.build();
}
Also used : IndexDocument(com.enonic.xp.repo.impl.elasticsearch.document.IndexDocument) PatternIndexConfigDocument(com.enonic.xp.index.PatternIndexConfigDocument) IndexConfigDocument(com.enonic.xp.index.IndexConfigDocument)

Example 2 with IndexDocument

use of com.enonic.xp.repo.impl.elasticsearch.document.IndexDocument in project xp by enonic.

the class StoreExecutor method execute.

public void execute(final Collection<IndexDocument> indexDocuments) {
    for (IndexDocument indexDocument : indexDocuments) {
        final String id = indexDocument.getId();
        final XContentBuilder xContentBuilder = StoreDocumentXContentBuilderFactory.create(indexDocument);
        final IndexRequest req = Requests.indexRequest().id(id).index(indexDocument.getIndexName()).type(indexDocument.getIndexTypeName()).source(xContentBuilder).refresh(indexDocument.isRefreshAfterOperation());
        try {
            this.client.index(req).actionGet(storeTimeout);
        } catch (Exception e) {
            final String msg = "Failed to store document with id [" + id + "] in index [" + indexDocument.getIndexName() + "] branch " + indexDocument.getIndexTypeName();
            LOG.error(msg, e);
            throw new IndexException(msg, e);
        }
    }
}
Also used : IndexDocument(com.enonic.xp.repo.impl.elasticsearch.document.IndexDocument) IndexException(com.enonic.xp.repository.IndexException) IndexRequest(org.elasticsearch.action.index.IndexRequest) XContentBuilder(org.elasticsearch.common.xcontent.XContentBuilder) IndexException(com.enonic.xp.repository.IndexException)

Example 3 with IndexDocument

use of com.enonic.xp.repo.impl.elasticsearch.document.IndexDocument in project xp by enonic.

the class NodeStoreDocumentFactoryTest method references.

@Test
public void references() throws Exception {
    final PropertyTree data = new PropertyTree();
    data.addReference("myRef", new Reference(NodeId.from("otherNode")));
    final Node node = Node.create().id(NodeId.from("myNodeId")).parentPath(NodePath.ROOT).name("myNode").data(data).build();
    final Collection<IndexDocument> indexDocuments = NodeStoreDocumentFactory.createBuilder().node(node).branch(Branch.from("myBranch")).repositoryId(RepositoryId.from("my-repo")).build().create();
    assertEquals(1, indexDocuments.size());
    final IndexDocument indexDocument = indexDocuments.iterator().next();
    final IndexItems indexItems = indexDocument.getIndexItems();
    final Collection<IndexValue> referenceValues = indexItems.get(NodeIndexPath.REFERENCE.getPath());
    assertEquals(1, referenceValues.size());
    final IndexValue next = referenceValues.iterator().next();
    assertTrue(next instanceof IndexValueString);
    final IndexValueString referenceValue = (IndexValueString) next;
    assertEquals("otherNode", referenceValue.getValue());
}
Also used : IndexDocument(com.enonic.xp.repo.impl.elasticsearch.document.IndexDocument) Reference(com.enonic.xp.util.Reference) PropertyTree(com.enonic.xp.data.PropertyTree) Node(com.enonic.xp.node.Node) IndexValueString(com.enonic.xp.repo.impl.elasticsearch.document.indexitem.IndexValueString) IndexItems(com.enonic.xp.repo.impl.elasticsearch.document.indexitem.IndexItems) IndexValue(com.enonic.xp.repo.impl.elasticsearch.document.indexitem.IndexValue) Test(org.junit.jupiter.api.Test)

Example 4 with IndexDocument

use of com.enonic.xp.repo.impl.elasticsearch.document.IndexDocument in project xp by enonic.

the class NodeIndexDocumentFactoryTest method set_analyzer.

@Test
public void set_analyzer() throws Exception {
    final String myAnalyzerName = "myAnalyzer";
    final Node node = Node.create().id(NodeId.from("abc")).indexConfigDocument(PatternIndexConfigDocument.create().analyzer(myAnalyzerName).defaultConfig(IndexConfig.MINIMAL).build()).build();
    final Collection<IndexDocument> indexDocuments = NodeStoreDocumentFactory.createBuilder().node(node).branch(TEST_BRANCH).repositoryId(TEST_REPOSITORY_ID).build().create();
    final IndexDocument indexDocument = getIndexDocumentOfType(indexDocuments, "test");
    assertEquals(myAnalyzerName, indexDocument.getAnalyzer());
}
Also used : IndexDocument(com.enonic.xp.repo.impl.elasticsearch.document.IndexDocument) Node(com.enonic.xp.node.Node) Test(org.junit.jupiter.api.Test)

Example 5 with IndexDocument

use of com.enonic.xp.repo.impl.elasticsearch.document.IndexDocument in project xp by enonic.

the class NodeIndexDocumentFactoryTest method validate_given_id_then_ok.

@Test
public void validate_given_id_then_ok() {
    Node node = Node.create().id(NodeId.from("abc")).build();
    final Collection<IndexDocument> indexDocuments = NodeStoreDocumentFactory.createBuilder().node(node).branch(TEST_BRANCH).repositoryId(TEST_REPOSITORY_ID).build().create();
    assertNotNull(indexDocuments);
}
Also used : IndexDocument(com.enonic.xp.repo.impl.elasticsearch.document.IndexDocument) Node(com.enonic.xp.node.Node) Test(org.junit.jupiter.api.Test)

Aggregations

IndexDocument (com.enonic.xp.repo.impl.elasticsearch.document.IndexDocument)8 Test (org.junit.jupiter.api.Test)6 Node (com.enonic.xp.node.Node)5 IndexItems (com.enonic.xp.repo.impl.elasticsearch.document.indexitem.IndexItems)2 XContentBuilder (org.elasticsearch.common.xcontent.XContentBuilder)2 PropertyTree (com.enonic.xp.data.PropertyTree)1 IndexConfigDocument (com.enonic.xp.index.IndexConfigDocument)1 PatternIndexConfigDocument (com.enonic.xp.index.PatternIndexConfigDocument)1 IndexValue (com.enonic.xp.repo.impl.elasticsearch.document.indexitem.IndexValue)1 IndexValueString (com.enonic.xp.repo.impl.elasticsearch.document.indexitem.IndexValueString)1 IndexException (com.enonic.xp.repository.IndexException)1 Reference (com.enonic.xp.util.Reference)1 IndexRequest (org.elasticsearch.action.index.IndexRequest)1