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();
}
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);
}
}
}
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());
}
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());
}
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);
}
Aggregations