Search in sources :

Example 71 with BulkRequest

use of org.graylog.shaded.elasticsearch7.org.elasticsearch.action.bulk.BulkRequest in project jmix by jmix-framework.

the class EntityIndexerImpl method deleteByGroupedIndexIds.

protected IndexResult deleteByGroupedIndexIds(Map<IndexConfiguration, Collection<String>> groupedIndexIds) {
    if (log.isDebugEnabled()) {
        Integer amountOfInstances = groupedIndexIds.values().stream().map(Collection::size).reduce(Integer::sum).orElse(0);
        log.debug("Prepared {} instances within {} entities", amountOfInstances, groupedIndexIds.keySet().size());
    }
    BulkRequest request = new BulkRequest();
    for (Map.Entry<IndexConfiguration, Collection<String>> entry : groupedIndexIds.entrySet()) {
        IndexConfiguration indexConfiguration = entry.getKey();
        for (String indexId : entry.getValue()) {
            addDeleteActionToBulkRequest(request, indexConfiguration, indexId);
        }
    }
    BulkResponse bulkResponse = request.requests().isEmpty() ? createNoopBulkResponse() : executeBulkRequest(request);
    return IndexResult.create(bulkResponse);
}
Also used : BulkRequest(org.elasticsearch.action.bulk.BulkRequest) BulkResponse(org.elasticsearch.action.bulk.BulkResponse) IndexConfiguration(io.jmix.search.index.IndexConfiguration)

Example 72 with BulkRequest

use of org.graylog.shaded.elasticsearch7.org.elasticsearch.action.bulk.BulkRequest in project jmix by jmix-framework.

the class EntityIndexingTest method indexCompositePk.

@Test
@DisplayName("Indexing of entity with Composite primary key")
public void indexCompositePk() {
    TestCompositeKey compositeKey = metadata.create(TestCompositeKey.class);
    compositeKey.setPkName("pkName");
    compositeKey.setPkVersion(1L);
    TestCompositePkEntity entity = metadata.create(TestCompositePkEntity.class);
    entity.setName("Composite PK entity");
    entity.setId(compositeKey);
    dataManager.save(entity);
    JsonNode jsonNode = TestJsonUtils.readJsonFromFile("indexing/test_content_composite_pk");
    TestBulkRequestIndexActionValidationData expectedIndexAction = new TestBulkRequestIndexActionValidationData("search_index_test_compositepkentity", idSerialization.idToString(Id.of(entity)), jsonNode);
    TestBulkRequestValidationData expectedData = new TestBulkRequestValidationData(Collections.singletonList(expectedIndexAction), Collections.emptyList());
    entityIndexer.index(entity);
    List<BulkRequest> bulkRequests = bulkRequestsTracker.getBulkRequests();
    TestBulkRequestValidationResult result = TestBulkRequestValidator.validate(Collections.singletonList(expectedData), bulkRequests);
    Assert.assertFalse(result.toString(), result.hasFailures());
}
Also used : BulkRequest(org.elasticsearch.action.bulk.BulkRequest) JsonNode(com.fasterxml.jackson.databind.JsonNode) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 73 with BulkRequest

use of org.graylog.shaded.elasticsearch7.org.elasticsearch.action.bulk.BulkRequest in project jmix by jmix-framework.

the class EntityIndexingTest method indexDeletedInstanceHardDelete.

@Test
@DisplayName("Indexing already deleted instance (Hard Delete)")
public void indexDeletedInstanceHardDelete() {
    TestRootEntityHD instance = metadata.create(TestRootEntityHD.class);
    instance.setName("Deleted");
    dataManager.save(instance);
    dataManager.remove(instance);
    entityIndexer.index(instance);
    List<BulkRequest> bulkRequests = bulkRequestsTracker.getBulkRequests();
    Assert.assertTrue(bulkRequests.isEmpty());
}
Also used : TestRootEntityHD(test_support.entity.TestRootEntityHD) BulkRequest(org.elasticsearch.action.bulk.BulkRequest) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 74 with BulkRequest

use of org.graylog.shaded.elasticsearch7.org.elasticsearch.action.bulk.BulkRequest in project jmix by jmix-framework.

the class EntityIndexingTest method indexUuidPk.

@Test
@DisplayName("Indexing of entity with UUID primary key")
public void indexUuidPk() {
    TestUuidPkEntity entity = metadata.create(TestUuidPkEntity.class);
    entity.setName("UUID PK entity");
    dataManager.save(entity);
    JsonNode jsonNode = TestJsonUtils.readJsonFromFile("indexing/test_content_uuid_pk");
    TestBulkRequestIndexActionValidationData expectedIndexAction = new TestBulkRequestIndexActionValidationData("search_index_test_uuidpkentity", idSerialization.idToString(Id.of(entity)), jsonNode);
    TestBulkRequestValidationData expectedData = new TestBulkRequestValidationData(Collections.singletonList(expectedIndexAction), Collections.emptyList());
    entityIndexer.index(entity);
    List<BulkRequest> bulkRequests = bulkRequestsTracker.getBulkRequests();
    TestBulkRequestValidationResult result = TestBulkRequestValidator.validate(Collections.singletonList(expectedData), bulkRequests);
    Assert.assertFalse(result.toString(), result.hasFailures());
}
Also used : BulkRequest(org.elasticsearch.action.bulk.BulkRequest) JsonNode(com.fasterxml.jackson.databind.JsonNode) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 75 with BulkRequest

use of org.graylog.shaded.elasticsearch7.org.elasticsearch.action.bulk.BulkRequest in project jmix by jmix-framework.

the class EntityIndexingTest method indexWithIndexablePredicate.

@Test
@DisplayName("Indexing instances passed indexable predicate only")
public void indexWithIndexablePredicate() {
    TestEntityForPredicate indexableInstance = metadata.create(TestEntityForPredicate.class);
    indexableInstance.setName("Indexable");
    indexableInstance.setEnumValue(TestEnum.OPEN);
    TestEntityForPredicate notIndexableInstance = metadata.create(TestEntityForPredicate.class);
    notIndexableInstance.setName("Not Indexable");
    notIndexableInstance.setEnumValue(TestEnum.CLOSED);
    dataManager.save(indexableInstance, notIndexableInstance);
    JsonNode jsonNode = TestJsonUtils.readJsonFromFile("indexing/test_content_entity_for_predicate");
    TestBulkRequestIndexActionValidationData expectedIndexAction = new TestBulkRequestIndexActionValidationData("search_index_test_entityforpredicate", idSerialization.idToString(Id.of(indexableInstance)), jsonNode);
    TestBulkRequestValidationData expectedData = new TestBulkRequestValidationData(Collections.singletonList(expectedIndexAction), Collections.emptyList());
    entityIndexer.indexCollection(Arrays.asList(indexableInstance, notIndexableInstance));
    List<BulkRequest> bulkRequests = bulkRequestsTracker.getBulkRequests();
    TestBulkRequestValidationResult result = TestBulkRequestValidator.validate(Collections.singletonList(expectedData), bulkRequests);
    Assert.assertFalse(result.toString(), result.hasFailures());
}
Also used : BulkRequest(org.elasticsearch.action.bulk.BulkRequest) JsonNode(com.fasterxml.jackson.databind.JsonNode) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Aggregations

BulkRequest (org.elasticsearch.action.bulk.BulkRequest)158 IndexRequest (org.elasticsearch.action.index.IndexRequest)77 BulkResponse (org.elasticsearch.action.bulk.BulkResponse)73 IOException (java.io.IOException)47 DeleteRequest (org.elasticsearch.action.delete.DeleteRequest)40 BulkItemResponse (org.elasticsearch.action.bulk.BulkItemResponse)28 RestHighLevelClient (org.elasticsearch.client.RestHighLevelClient)27 UpdateRequest (org.elasticsearch.action.update.UpdateRequest)25 ArrayList (java.util.ArrayList)24 List (java.util.List)18 SearchRequest (org.elasticsearch.action.search.SearchRequest)17 Test (org.junit.jupiter.api.Test)17 DocWriteRequest (org.elasticsearch.action.DocWriteRequest)16 DeleteIndexRequest (org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest)16 Map (java.util.Map)15 Test (org.junit.Test)15 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)14 JsonNode (com.fasterxml.jackson.databind.JsonNode)14 BulkProcessor (org.elasticsearch.action.bulk.BulkProcessor)13 ActionListener (org.elasticsearch.action.ActionListener)12