<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic [TEST] [LTS-2023] elasticsearch instance not indexing documents in Nuxeo Forum</title>
    <link>https://connect.hyland.com/t5/nuxeo-forum/test-lts-2023-elasticsearch-instance-not-indexing-documents/m-p/493556#M15874</link>
    <description>&lt;P&gt;hallo,&lt;/P&gt;&lt;P&gt;i am currently trying to test the use of &lt;STRONG&gt;ElasticSearchService.scroll&lt;/STRONG&gt; combined with the &lt;STRONG&gt;WorkManager.schedule&lt;/STRONG&gt; to query document instead of using &lt;STRONG&gt;CoreSession.query&lt;/STRONG&gt;, it does not seem to index documents either created of modified&lt;/P&gt;&lt;P&gt;currently:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;through debugging in real situation i was able to confirm that the work planned executes properly under normal circumstances&amp;nbsp;&lt;/LI&gt;&lt;LI&gt;debugging the test reveals that the event triggers &lt;STRONG&gt;ElasticSearchService.scroll&lt;/STRONG&gt;, but no result is returned&lt;/LI&gt;&lt;LI&gt;&lt;STRONG&gt;SELECT * FROM CustomType&lt;/STRONG&gt;&amp;nbsp;query return nothing, even though the document is created beforehand (&lt;STRONG&gt;CoreSession.createDocument&lt;/STRONG&gt; assigns an ID to the template)&lt;/LI&gt;&lt;LI&gt;here is my test&lt;/LI&gt;&lt;/UL&gt;&lt;LI-CODE lang="java"&gt;  
  public void should_ArchiveDocument_WhenStale() throws IOException {

    // given an stale document
    final var template = session.createDocumentModel("/", "custom", "CustomType");
    final var midnight = ZonedDateTime.now().with(LocalTime.MIDNIGHT);
    final var yesterday = GregorianCalendar.from(midnight.minusDays(1));
    template.setPropertyValye("custom:date", yesterday); 
    session.createDocument(template);
    session.save();
    awaitCompletion();

    // when archiving
    eventService.fireEvent(
        "scheduled_archiving", 
        new EventContextImpl(session, session.getPrincipal()));

    awaitCompletion();

    // then document is archived
    final var expected = session.query(ARCHIVED)
        .stream().map(CustomType::new)
        .toList();

    Assertions.assertThat(expected)
        .describedAs("should archive the document")
        .hasSize(1) // fails here with 0 elements
        .element(0)
        .matches(it -&amp;gt; "custom".equals(it.getTitle()), "should be named 'custom'")
        .matches(it -&amp;gt; "archived".equals(it.state()), "should be archived");

  }

  private void awaitCompletion() {
    eventService.waitForAsyncCompletion();
    Awaitility.await("WorkManager.awaitCompletion")
        .atMost(Duration.FIVE_SECONDS)
        .pollInterval(100, TimeUnit.MILLISECONDS)
        .until(() -&amp;gt; workManager.awaitCompletion(99, TimeUnit.MILLISECONDS));
    elasticSearchAdmin.prepareWaitForIndexing().get();
    elasticSearchAdmin.refresh();
  }&lt;/LI-CODE&gt;&lt;UL&gt;&lt;LI&gt;i am deploying this for my tests&lt;/LI&gt;&lt;/UL&gt;&lt;LI-CODE lang="java"&gt;@RunWith(FeaturesRunner.class)
@Features({
    MockitoFeature.class,
    RestServerFeature.class,
    RuntimeStreamFeature.class,
    RepositoryElasticSearchFeature.class })
@Deploy("org.nuxeo.ecm.jwt")
@Deploy("org.nuxeo.ecm.core.management")
@Deploy("org.nuxeo.ecm.default.config")
@Deploy("org.nuxeo.ecm.platform.suggestbox.core")
@Deploy("org.nuxeo.ecm.platform.thumbnail")
@Deploy("org.nuxeo.ecm.platform.convert")
@Deploy("org.nuxeo.ecm.platform.rendition.core")
@Deploy("org.nuxeo.ecm.platform.io.core")
@Deploy("org.nuxeo.ecm.platform.notification")
@Deploy("org.nuxeo.web.resources.core")
@Deploy("studio.extensions.my-studio-project")
@Deploy("my-core-bundle-symbolic-name")
@Deploy("my-core-bundle-symbolic-name-test:OSGI-INF/default-general-settings-contrib.xml")&lt;/LI-CODE&gt;&lt;UL&gt;&lt;LI&gt;&amp;nbsp;this is what is executed from the triggered event&lt;/LI&gt;&lt;/UL&gt;&lt;LI-CODE lang="java"&gt;    documentService.scrollAndSchedule(
        session, 
        "SELECT * FROM CustomType WHERE archive:date &amp;lt; NOW()", 
        documents -&amp;gt; {
            for (final var document : documents) {
                session.followTransition(document, "archiving");
                session.saveDocument(document);
            }
        }
    );&lt;/LI-CODE&gt;&lt;UL&gt;&lt;LI&gt;here is the method being called&lt;/LI&gt;&lt;/UL&gt;&lt;LI-CODE lang="java"&gt;    
    public Set&amp;lt;String&amp;gt; scrollAndSchedule(
        final CoreSession session,
        final String query, 
        final Consumer&amp;lt;EsScrollResult&amp;gt; consumer) {

        // Get the ElasticSearchService
        final var ess = Framework.getService(ElasticSearchService.class);
        final var workManager = Framework.getService(WorkManager.class);

        // Build the NXQL query with pagination settings
        final var nxql = new NxQueryBuilder(session)
                .nxql(query).fetchFromElasticsearch()
                .limit(CoreConstants.queryLimit());

        // Initialize the scroll with the NXQL query
        var response = ess.scroll(nxql, CoreConstants.queryTimeout());

        try {

            // Initialize the page counter
            var pages = 0;

            // Initalize the work IDs set
            final var works = new HashSet&amp;lt;String&amp;gt;();

            // Loop through the recovered documents page 
            // until there are no more documents 
            // or the upper limit is reached
            while (!response.getDocuments().isEmpty() &amp;amp;&amp;amp; pages &amp;lt; CoreConstants.LOOP_UPPER_LIMIT) {

                // create the work to be excuted in an asynchronous parallel manner
                // TODO: use the bulk action framework
                final var work = ConsumerWork.&amp;lt;EsScrollResult&amp;gt;builder()
                        .data(response)
                        .consumer(consumer)
                        .build();

                // Add the work ID to the set of works
                works.add(work.getId());

                // executes the consumer function on the current page of documents
                workManager.schedule(work);

                // Scroll to the next page of documents
                response = ess.scroll(response);

                // Increment the number of pages processed
                pages++;
            }

            return works;

        } finally {

            // Clear the scroll context to free resources
            ess.clearScroll(response);
        }
    }&lt;/LI-CODE&gt;&lt;UL&gt;&lt;LI&gt;here is the work used&lt;/LI&gt;&lt;/UL&gt;&lt;LI-CODE lang="java"&gt;@Slf4j
@Setter
@Accessors(fluent = true)
@EqualsAndHashCode(callSuper = true)
public class ConsumerWork&amp;lt;T&amp;gt; extends AbstractWork {

  private static final long serialVersionUID = ClassUtils.hash(ConsumerWork.class);

  private final transient T data;
  private final transient Consumer&amp;lt;T&amp;gt; consumer;

  @Builder
  public ConsumerWork(
      T data,
      Consumer&amp;lt;T&amp;gt; consumer) {
    super(UUID.randomUUID().toString());
    this.data = data;
    this.data = data;
  }

  
  public String getTitle() {
    return String.format("Consuming data with id [%s]", getId());
  }

  
  public void work() {
    if (ObjectUtils.allNotNull(data, consumer)) {
      consumer.accept(data);
    } else {
      log.warn("[data] or [consumer] was not provided");
    }
  }

  
  public String getCategory() {
    return "consumeData";
  }

}&lt;/LI-CODE&gt;&lt;P&gt;the results i am getting currently:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;when using &lt;STRONG&gt;CoreSession.query&lt;/STRONG&gt; it passes&lt;/LI&gt;&lt;LI&gt;with&amp;nbsp;&lt;STRONG&gt;ElasticSearchService.scroll&lt;/STRONG&gt;, no exception is thrown, it simply expects 1 archived element and finds none&lt;/LI&gt;&lt;/UL&gt;</description>
    <pubDate>Mon, 13 Oct 2025 16:00:13 GMT</pubDate>
    <dc:creator>cheshire</dc:creator>
    <dc:date>2025-10-13T16:00:13Z</dc:date>
    <item>
      <title>[TEST] [LTS-2023] elasticsearch instance not indexing documents</title>
      <link>https://connect.hyland.com/t5/nuxeo-forum/test-lts-2023-elasticsearch-instance-not-indexing-documents/m-p/493556#M15874</link>
      <description>&lt;P&gt;hallo,&lt;/P&gt;&lt;P&gt;i am currently trying to test the use of &lt;STRONG&gt;ElasticSearchService.scroll&lt;/STRONG&gt; combined with the &lt;STRONG&gt;WorkManager.schedule&lt;/STRONG&gt; to query document instead of using &lt;STRONG&gt;CoreSession.query&lt;/STRONG&gt;, it does not seem to index documents either created of modified&lt;/P&gt;&lt;P&gt;currently:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;through debugging in real situation i was able to confirm that the work planned executes properly under normal circumstances&amp;nbsp;&lt;/LI&gt;&lt;LI&gt;debugging the test reveals that the event triggers &lt;STRONG&gt;ElasticSearchService.scroll&lt;/STRONG&gt;, but no result is returned&lt;/LI&gt;&lt;LI&gt;&lt;STRONG&gt;SELECT * FROM CustomType&lt;/STRONG&gt;&amp;nbsp;query return nothing, even though the document is created beforehand (&lt;STRONG&gt;CoreSession.createDocument&lt;/STRONG&gt; assigns an ID to the template)&lt;/LI&gt;&lt;LI&gt;here is my test&lt;/LI&gt;&lt;/UL&gt;&lt;LI-CODE lang="java"&gt;  
  public void should_ArchiveDocument_WhenStale() throws IOException {

    // given an stale document
    final var template = session.createDocumentModel("/", "custom", "CustomType");
    final var midnight = ZonedDateTime.now().with(LocalTime.MIDNIGHT);
    final var yesterday = GregorianCalendar.from(midnight.minusDays(1));
    template.setPropertyValye("custom:date", yesterday); 
    session.createDocument(template);
    session.save();
    awaitCompletion();

    // when archiving
    eventService.fireEvent(
        "scheduled_archiving", 
        new EventContextImpl(session, session.getPrincipal()));

    awaitCompletion();

    // then document is archived
    final var expected = session.query(ARCHIVED)
        .stream().map(CustomType::new)
        .toList();

    Assertions.assertThat(expected)
        .describedAs("should archive the document")
        .hasSize(1) // fails here with 0 elements
        .element(0)
        .matches(it -&amp;gt; "custom".equals(it.getTitle()), "should be named 'custom'")
        .matches(it -&amp;gt; "archived".equals(it.state()), "should be archived");

  }

  private void awaitCompletion() {
    eventService.waitForAsyncCompletion();
    Awaitility.await("WorkManager.awaitCompletion")
        .atMost(Duration.FIVE_SECONDS)
        .pollInterval(100, TimeUnit.MILLISECONDS)
        .until(() -&amp;gt; workManager.awaitCompletion(99, TimeUnit.MILLISECONDS));
    elasticSearchAdmin.prepareWaitForIndexing().get();
    elasticSearchAdmin.refresh();
  }&lt;/LI-CODE&gt;&lt;UL&gt;&lt;LI&gt;i am deploying this for my tests&lt;/LI&gt;&lt;/UL&gt;&lt;LI-CODE lang="java"&gt;@RunWith(FeaturesRunner.class)
@Features({
    MockitoFeature.class,
    RestServerFeature.class,
    RuntimeStreamFeature.class,
    RepositoryElasticSearchFeature.class })
@Deploy("org.nuxeo.ecm.jwt")
@Deploy("org.nuxeo.ecm.core.management")
@Deploy("org.nuxeo.ecm.default.config")
@Deploy("org.nuxeo.ecm.platform.suggestbox.core")
@Deploy("org.nuxeo.ecm.platform.thumbnail")
@Deploy("org.nuxeo.ecm.platform.convert")
@Deploy("org.nuxeo.ecm.platform.rendition.core")
@Deploy("org.nuxeo.ecm.platform.io.core")
@Deploy("org.nuxeo.ecm.platform.notification")
@Deploy("org.nuxeo.web.resources.core")
@Deploy("studio.extensions.my-studio-project")
@Deploy("my-core-bundle-symbolic-name")
@Deploy("my-core-bundle-symbolic-name-test:OSGI-INF/default-general-settings-contrib.xml")&lt;/LI-CODE&gt;&lt;UL&gt;&lt;LI&gt;&amp;nbsp;this is what is executed from the triggered event&lt;/LI&gt;&lt;/UL&gt;&lt;LI-CODE lang="java"&gt;    documentService.scrollAndSchedule(
        session, 
        "SELECT * FROM CustomType WHERE archive:date &amp;lt; NOW()", 
        documents -&amp;gt; {
            for (final var document : documents) {
                session.followTransition(document, "archiving");
                session.saveDocument(document);
            }
        }
    );&lt;/LI-CODE&gt;&lt;UL&gt;&lt;LI&gt;here is the method being called&lt;/LI&gt;&lt;/UL&gt;&lt;LI-CODE lang="java"&gt;    
    public Set&amp;lt;String&amp;gt; scrollAndSchedule(
        final CoreSession session,
        final String query, 
        final Consumer&amp;lt;EsScrollResult&amp;gt; consumer) {

        // Get the ElasticSearchService
        final var ess = Framework.getService(ElasticSearchService.class);
        final var workManager = Framework.getService(WorkManager.class);

        // Build the NXQL query with pagination settings
        final var nxql = new NxQueryBuilder(session)
                .nxql(query).fetchFromElasticsearch()
                .limit(CoreConstants.queryLimit());

        // Initialize the scroll with the NXQL query
        var response = ess.scroll(nxql, CoreConstants.queryTimeout());

        try {

            // Initialize the page counter
            var pages = 0;

            // Initalize the work IDs set
            final var works = new HashSet&amp;lt;String&amp;gt;();

            // Loop through the recovered documents page 
            // until there are no more documents 
            // or the upper limit is reached
            while (!response.getDocuments().isEmpty() &amp;amp;&amp;amp; pages &amp;lt; CoreConstants.LOOP_UPPER_LIMIT) {

                // create the work to be excuted in an asynchronous parallel manner
                // TODO: use the bulk action framework
                final var work = ConsumerWork.&amp;lt;EsScrollResult&amp;gt;builder()
                        .data(response)
                        .consumer(consumer)
                        .build();

                // Add the work ID to the set of works
                works.add(work.getId());

                // executes the consumer function on the current page of documents
                workManager.schedule(work);

                // Scroll to the next page of documents
                response = ess.scroll(response);

                // Increment the number of pages processed
                pages++;
            }

            return works;

        } finally {

            // Clear the scroll context to free resources
            ess.clearScroll(response);
        }
    }&lt;/LI-CODE&gt;&lt;UL&gt;&lt;LI&gt;here is the work used&lt;/LI&gt;&lt;/UL&gt;&lt;LI-CODE lang="java"&gt;@Slf4j
@Setter
@Accessors(fluent = true)
@EqualsAndHashCode(callSuper = true)
public class ConsumerWork&amp;lt;T&amp;gt; extends AbstractWork {

  private static final long serialVersionUID = ClassUtils.hash(ConsumerWork.class);

  private final transient T data;
  private final transient Consumer&amp;lt;T&amp;gt; consumer;

  @Builder
  public ConsumerWork(
      T data,
      Consumer&amp;lt;T&amp;gt; consumer) {
    super(UUID.randomUUID().toString());
    this.data = data;
    this.data = data;
  }

  
  public String getTitle() {
    return String.format("Consuming data with id [%s]", getId());
  }

  
  public void work() {
    if (ObjectUtils.allNotNull(data, consumer)) {
      consumer.accept(data);
    } else {
      log.warn("[data] or [consumer] was not provided");
    }
  }

  
  public String getCategory() {
    return "consumeData";
  }

}&lt;/LI-CODE&gt;&lt;P&gt;the results i am getting currently:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;when using &lt;STRONG&gt;CoreSession.query&lt;/STRONG&gt; it passes&lt;/LI&gt;&lt;LI&gt;with&amp;nbsp;&lt;STRONG&gt;ElasticSearchService.scroll&lt;/STRONG&gt;, no exception is thrown, it simply expects 1 archived element and finds none&lt;/LI&gt;&lt;/UL&gt;</description>
      <pubDate>Mon, 13 Oct 2025 16:00:13 GMT</pubDate>
      <guid>https://connect.hyland.com/t5/nuxeo-forum/test-lts-2023-elasticsearch-instance-not-indexing-documents/m-p/493556#M15874</guid>
      <dc:creator>cheshire</dc:creator>
      <dc:date>2025-10-13T16:00:13Z</dc:date>
    </item>
  </channel>
</rss>

