All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.searchbox.core.ClearScroll Maven / Gradle / Ivy

There is a newer version: 6.3.1
Show newest version
package io.searchbox.core;

import com.google.common.collect.ImmutableMap;
import io.searchbox.action.GenericResultAbstractAction;

import java.util.Collection;
import java.util.LinkedHashSet;
import java.util.Set;


public class ClearScroll extends GenericResultAbstractAction {

  private final String uri;

  public ClearScroll(Builder builder) {

    if (builder.getScrollIds().size() == 0) {
      uri = "/_search/scroll/_all";
      this.payload = null;
    } else {
      uri = "/_search/scroll";
      this.payload = ImmutableMap.of("scroll_id", builder.getScrollIds());
    }

    setURI(buildURI());
  }

  @Override
  public String getRestMethodName() {
    return "DELETE";
  }

  @Override
  protected String buildURI() {
    return super.buildURI() + uri;
  }

  public static class Builder extends GenericResultAbstractAction.Builder {

    protected Collection scrollIds = new LinkedHashSet();

    public Builder addScrollId(String scrollId) {
      this.scrollIds.add(scrollId);
      return this;
    }

    public Builder addScrollIds(Set scrollIds) {
      this.scrollIds.addAll(scrollIds);
      return this;
    }

    @Override
    public ClearScroll build() {
      return new ClearScroll(this);
    }

    public Collection getScrollIds() {
      return scrollIds;
    }

  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy