org.elasticsearch.action.admin.indices.refresh.RefreshRequest Java Examples

The following examples show how to use org.elasticsearch.action.admin.indices.refresh.RefreshRequest. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: XmlPluginTest.java    From elasticsearch-xml with Apache License 2.0 6 votes vote down vote up
@Test
public void testBigAndFatResponse() throws Exception {
    Client client = client("1");
    for (int i = 0; i < 10000; i++) {
        client.index(new IndexRequest("test", "test", Integer.toString(i))
                .source("{\"random\":\""+randomString(32)+ " " + randomString(32) + "\"}")).actionGet();
    }
    client.admin().indices().refresh(new RefreshRequest("test")).actionGet();
    InetSocketTransportAddress httpAddress = findHttpAddress(client);
    if (httpAddress == null) {
        throw new IllegalArgumentException("no HTTP address found");
    }
    URL base = new URL("http://" + httpAddress.getHost() + ":" + httpAddress.getPort());
    URL url = new URL(base, "/test/test/_search?xml&pretty&size=10000");
    BufferedReader reader = new BufferedReader(new InputStreamReader(url.openStream()));
    int count = 0;
    String line;
    while ((line = reader.readLine()) != null) {
        count += line.length();
    }
    assertTrue(count >= 2309156);
    reader.close();
    client.admin().indices().delete(new DeleteIndexRequest("test"));
}
 
Example #2
Source File: ElasticSearchComponent.java    From metron with Apache License 2.0 6 votes vote down vote up
public List<Map<String, Object>> getAllIndexedDocs(String index, String sourceType,
    String subMessage) throws IOException {
  getClient().admin().indices().refresh(new RefreshRequest());
  SearchResponse response = getClient().prepareSearch(index)
      .setTypes(sourceType)
      .setFrom(0)
      .setSize(1000)
      .execute().actionGet();
  List<Map<String, Object>> ret = new ArrayList<Map<String, Object>>();
  for (SearchHit hit : response.getHits()) {
    Object o = null;
    if (subMessage == null) {
      o = hit.getSource();
    } else {
      o = hit.getSource().get(subMessage);
    }
    ret.add((Map<String, Object>) (o));
  }
  return ret;
}
 
Example #3
Source File: RestHighLevelClientCase.java    From skywalking with Apache License 2.0 6 votes vote down vote up
public boolean elasticsearch() throws Exception {
    String indexName = UUID.randomUUID().toString();
    try {
        //create
        createIndex(client, indexName);
        // index
        index(client, indexName);

        client.indices().refresh(new RefreshRequest(indexName), RequestOptions.DEFAULT);

        //get
        get(client, indexName);
        // search
        search(client, indexName);
        // update
        update(client, indexName);
        // delete
        delete(client, indexName);
    } finally {
        if (null != client) {
            client.close();
        }
    }
    return true;
}
 
Example #4
Source File: AbstractIMAPRiverUnitTest.java    From elasticsearch-imap with Apache License 2.0 6 votes vote down vote up
protected long getCount(final List<String> indices, final String type) {
    logger.debug("getCount() for index {} and type", indices, type);
    
    esSetup.client().admin().indices().refresh(new RefreshRequest()).actionGet();

    long count = 0;
    
    for (Iterator<String> iterator = indices.iterator(); iterator.hasNext();) {
        String index = (String) iterator.next();
         long lcount = esSetup.client().count(new CountRequest(index).types(type)).actionGet().getCount();
         logger.debug("Count for index {} (type {}) is {}", index, type, lcount);
         count += lcount;
    }

    return count;
}
 
Example #5
Source File: IndexTransaction.java    From es-service-parent with Apache License 2.0 6 votes vote down vote up
/**
 * 删除文档
 * 
 * @param id
 */
public boolean deleteDocById(String docId) {
    try {
        // 删除
        DeleteResponse resp = ESClient.getClient()
                .prepareDelete(this.currentIndexName, this.indexType.getTypeName(), docId)
                .setOperationThreaded(false).execute().actionGet();
        // 刷新
        ESClient.getClient().admin().indices()
                .refresh(new RefreshRequest(this.currentIndexName)).actionGet();
        if (resp.isFound()) {
            log.warn("delete index sunccess,indexname:{},type:{},delete {} items",
                    this.indexType.getIndexName(), this.indexType.getTypeName(), 1);
            return resp.isFound();
        }
    } catch (Exception e) {
        log.error("delete Doc fail,indexname:{},type:{}", this.indexType.getIndexName(),
                this.indexType.getTypeName());
    }
    return false;
}
 
Example #6
Source File: MockElasticsearchServer.java    From foxtrot with Apache License 2.0 5 votes vote down vote up
public void refresh(final String index) {
    node.client()
            .admin()
            .indices()
            .refresh(new RefreshRequest().indices(index))
            .actionGet();
}
 
Example #7
Source File: CaseController.java    From skywalking with Apache License 2.0 5 votes vote down vote up
@GetMapping("/elasticsearch")
public String elasticsearch() throws Exception {
    String indexName = UUID.randomUUID().toString();
    try {
        // health
        health();
        
        // get settings
        getSettings();
        
        // put settings
        putSettings();
        
        // create
        createIndex(indexName);
        
        // index
        index(indexName);

        client.indices().refresh(new RefreshRequest(indexName), RequestOptions.DEFAULT);

        // get
        get(indexName);
        
        // search
        search(indexName);
        
        // update
        update(indexName);
        
        // delete
        delete(indexName);
    } finally {
        if (null != client) {
            client.close();
        }
    }
    return "Success";
}
 
Example #8
Source File: ElasticsearchMailDestination.java    From elasticsearch-imap with Apache License 2.0 5 votes vote down vote up
@Override
public Set<String> getFolderNames() throws IOException, MessagingException {

    createIndexIfNotExists();
    
    client.admin().indices().refresh(new RefreshRequest()).actionGet();

    final HashSet<String> uids = new HashSet<String>();

    SearchResponse scrollResp = client.prepareSearch().setIndices(index).setTypes(type).setSearchType(SearchType.SCAN)
            .setQuery(QueryBuilders.matchAllQuery()).addField("folderFullName").setScroll(new TimeValue(1000)).setSize(1000).execute()
            .actionGet();

    while (true) {
        scrollResp = client.prepareSearchScroll(scrollResp.getScrollId()).setScroll(new TimeValue(1000)).execute().actionGet();
        boolean hitsRead = false;
        for (final SearchHit hit : scrollResp.getHits()) {
            hitsRead = true;
            uids.add((String) hit.getFields().get("folderFullName").getValue());

        }
        if (!hitsRead) {
            break;
        }
    }

    if (logger.isDebugEnabled()) {
        logger.debug("Currently locally stored folders: {}", uids);
    }

    return uids;

}
 
Example #9
Source File: ElasticsearchTemplateRecordConsumerTest.java    From baleen with Apache License 2.0 5 votes vote down vote up
@Before
public void beforeElasticsearchRecordConsumerTest() throws Exception {

  elasticsearch = new EmbeddedElasticsearch5();

  ExternalResourceDescription erd =
      ExternalResourceFactory.createNamedResourceDescription(
          RESOURCE_KEY,
          SharedElasticsearchRestResource.class,
          PARAM_URL,
          elasticsearch.getHttpUrl());

  analysisEngine = getAnalysisEngine(RESOURCE_KEY, erd);
  elasticsearch.client().admin().indices().refresh(new RefreshRequest(BALEEN_INDEX)).actionGet();
}
 
Example #10
Source File: IndexTransaction.java    From es-service-parent with Apache License 2.0 5 votes vote down vote up
/**
 * 编入索引
 * 
 * @param jsonObject
 * @return
 */
public int indexed(String jsonObject) {
    if (Constants.isDebug) {
        log.debug(jsonObject);
    }
    if (null == this.bulkRequest) {
        this.bulkRequest = ESClient.getClient().prepareBulk();
    } else {
        // 批量提交
        if (this.bulkRequest.numberOfActions() >= BULK_REQUEST_MAX_NUM) {
            long start = System.currentTimeMillis();
            BulkResponse actionGet = this.bulkRequest.execute().actionGet();
            if (actionGet.hasFailures()) {
                // 失败
                log.error(actionGet.buildFailureMessage());
            }
            long end = System.currentTimeMillis();
            log.warn("bulkRequest commit {} indexed,time in {}", this.currentIndexName,
                    (end - start));
            this.bulkRequest = ESClient.getClient().prepareBulk();
            // 增量可保持实时搜索
            ESClient.getClient().admin().indices()
                    .refresh(new RefreshRequest(this.currentIndexName)).actionGet();
            // ESClient.getClient().admin().indices().flush(new FlushRequest(this.currentIndexName)).actionGet();
        }
    }
    this.bulkRequest
            .add(ESClient.getClient()
                    .prepareIndex(this.currentIndexName, indexType.getTypeName())
                    .setSource(jsonObject));
    return 0;
}
 
Example #11
Source File: BaseClient.java    From elasticsearch-helper with Apache License 2.0 5 votes vote down vote up
public void refreshIndex(String index) {
    if (client() == null) {
        return;
    }
    if (index != null) {
        client().execute(RefreshAction.INSTANCE, new RefreshRequest(index)).actionGet();
    }
}
 
Example #12
Source File: RestRefreshAction.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
@Override
public void handleRequest(final RestRequest request, final RestChannel channel, final Client client) {
    RefreshRequest refreshRequest = new RefreshRequest(Strings.splitStringByCommaToArray(request.param("index")));
    refreshRequest.indicesOptions(IndicesOptions.fromRequest(request, refreshRequest.indicesOptions()));
    client.admin().indices().refresh(refreshRequest, new RestBuilderListener<RefreshResponse>(channel) {
        @Override
        public RestResponse buildResponse(RefreshResponse response, XContentBuilder builder) throws Exception {
            builder.startObject();
            buildBroadcastShardsHeader(builder, request, response);
            builder.endObject();
            return new BytesRestResponse(OK, builder);
        }
    });
}
 
Example #13
Source File: RefreshRequestBuilder.java    From elasticshell with Apache License 2.0 5 votes vote down vote up
@Override
protected XContentBuilder toXContent(RefreshRequest request, RefreshResponse response, XContentBuilder builder) throws IOException {
    builder.startObject();
    builder.field(Fields.OK, true);
    buildBroadcastShardsHeader(builder, response);
    builder.endObject();
    return builder;
}
 
Example #14
Source File: DDLStatementDispatcher.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
@Override
public ListenableFuture<Long> visitRefreshTableStatement(RefreshTableAnalyzedStatement analysis, SingleJobTask jobId) {
    if (analysis.indexNames().isEmpty()) {
        return Futures.immediateFuture(null);
    }
    RefreshRequest request = new RefreshRequest(analysis.indexNames().toArray(
            new String[analysis.indexNames().size()]));
    request.indicesOptions(IndicesOptions.lenientExpandOpen());

    final SettableFuture<Long> future = SettableFuture.create();
    ActionListener<RefreshResponse> listener = ActionListeners.wrap(future, Functions.<Long>constant(new Long(analysis.indexNames().size())));
    transportActionProvider.transportRefreshAction().execute(request, listener);
    return future;
}
 
Example #15
Source File: RefreshRequestBuilder.java    From elasticshell with Apache License 2.0 4 votes vote down vote up
public RefreshRequestBuilder(Client client, JsonToString<JsonInput> jsonToString, StringToJson<JsonOutput> stringToJson) {
    super(client, new RefreshRequest(), jsonToString, stringToJson);
}
 
Example #16
Source File: RefreshRequestBuilder.java    From elasticshell with Apache License 2.0 4 votes vote down vote up
@Override
protected ActionFuture<RefreshResponse> doExecute(RefreshRequest request) {
    return client.admin().indices().refresh(request);
}
 
Example #17
Source File: AbstractClient.java    From crate with Apache License 2.0 4 votes vote down vote up
@Override
public ActionFuture<RefreshResponse> refresh(final RefreshRequest request) {
    return execute(RefreshAction.INSTANCE, request);
}
 
Example #18
Source File: AbstractClient.java    From crate with Apache License 2.0 4 votes vote down vote up
@Override
public void refresh(final RefreshRequest request, final ActionListener<RefreshResponse> listener) {
    execute(RefreshAction.INSTANCE, request, listener);
}
 
Example #19
Source File: ElasticsearchMailDestination.java    From elasticsearch-imap with Apache License 2.0 4 votes vote down vote up
@Override
public int getFlaghashcode(final String id) throws IOException, MessagingException {

    createIndexIfNotExists();
    
    client.admin().indices().refresh(new RefreshRequest()).actionGet();

    final GetResponse getResponse = client.prepareGet().setIndex(index).setType(type).setId(id)
            .setFields(new String[] { "flaghashcode" }).execute().actionGet();

    if (getResponse == null || !getResponse.isExists()) {
        return -1;
    }

    final GetField flaghashcodeField = getResponse.getField("flaghashcode");

    if (flaghashcodeField == null || flaghashcodeField.getValue() == null || !(flaghashcodeField.getValue() instanceof Number)) {
        throw new IOException("No flaghashcode field for id " + id+ " ("+(flaghashcodeField==null?"null":"Val: "+flaghashcodeField.getValue())+")");
    }

    return ((Number) flaghashcodeField.getValue()).intValue();

}
 
Example #20
Source File: RefreshTablePlan.java    From crate with Apache License 2.0 4 votes vote down vote up
@Override
public void executeOrFail(DependencyCarrier dependencies,
                          PlannerContext plannerContext,
                          RowConsumer consumer,
                          Row parameters,
                          SubQueryResults subQueryResults) {
    if (analysis.tables().isEmpty()) {
        consumer.accept(InMemoryBatchIterator.empty(SENTINEL), null);
        return;
    }

    Function<? super Symbol, Object> eval = x -> SymbolEvaluator.evaluate(
        plannerContext.transactionContext(),
        plannerContext.functions(),
        x,
        parameters,
        subQueryResults
    );

    ArrayList<String> toRefresh = new ArrayList<>();
    for (Map.Entry<Table<Symbol>, DocTableInfo> table : analysis.tables().entrySet()) {
        var tableInfo = table.getValue();
        var tableSymbol = table.getKey();
        if (tableSymbol.partitionProperties().isEmpty()) {
            toRefresh.addAll(Arrays.asList(tableInfo.concreteOpenIndices()));
        } else {
            var partitionName = toPartitionName(
                tableInfo,
                Lists2.map(tableSymbol.partitionProperties(), p -> p.map(eval)));
            if (!tableInfo.partitions().contains(partitionName)) {
                throw new PartitionUnknownException(partitionName);
            }
            toRefresh.add(partitionName.asIndexName());
        }
    }

    RefreshRequest request = new RefreshRequest(toRefresh.toArray(String[]::new));
    request.indicesOptions(IndicesOptions.lenientExpandOpen());

    var transportRefreshAction = dependencies.transportActionProvider().transportRefreshAction();
    transportRefreshAction.execute(
        request,
        new OneRowActionListener<>(
            consumer,
            response -> new Row1(toRefresh.isEmpty() ? -1L : (long) toRefresh.size())
        )
    );
}
 
Example #21
Source File: ElasticsearchMailDestination.java    From elasticsearch-imap with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings({ "rawtypes", "unchecked" })
@Override
public Set getCurrentlyStoredMessageUids(final Folder folder) throws IOException, MessagingException {

    createIndexIfNotExists();
    
    client.admin().indices().refresh(new RefreshRequest()).actionGet();

    final Set uids = new HashSet();

    final TermQueryBuilder b = QueryBuilders.termQuery("folderUri", folder.getURLName().toString());

    logger.debug("Term query: " + b.buildAsBytes().toUtf8());

    SearchResponse scrollResp = client.prepareSearch().setIndices(index).setTypes(type).setSearchType(SearchType.SCAN).setQuery(b)
            .setScroll(new TimeValue(1000)).setSize(1000).execute().actionGet();

    while (true) {
        scrollResp = client.prepareSearchScroll(scrollResp.getScrollId()).setScroll(new TimeValue(1000)).execute().actionGet();
        boolean hitsRead = false;
        for (final SearchHit hit : scrollResp.getHits()) {
            hitsRead = true;

            if (folder instanceof IMAPFolder) {
                uids.add(Long.parseLong(hit.getId().split("::")[0]));
            } else {
                uids.add(hit.getId().split("::")[0]);
            }

            logger.debug("Local: " + hit.getId());
        }
        if (!hitsRead) {
            break;
        }
    }

    logger.debug("Currently locally stored messages for folder {}: {}", folder.getURLName(), uids.size());

    return uids;

}
 
Example #22
Source File: BaseElasticSearchIndexBuilder.java    From sakai with Educational Community License v2.0 4 votes vote down vote up
/**
 * refresh the index from the current stored state {@inheritDoc}
 */
public void refreshIndex() {
    RefreshResponse response = client.admin().indices().refresh(new RefreshRequest(indexName)).actionGet();
}
 
Example #23
Source File: InternalEsClient.java    From io with Apache License 2.0 4 votes vote down vote up
/**
 * 引数で指定されたインデックスに対してrefreshする.
 * @param index インデックス名
 * @return レスポンス
 */
public DcRefreshResponse refresh(String index) {
    RefreshResponse response = esTransportClient.admin().indices()
            .refresh(new RefreshRequest(index)).actionGet();
    return DcRefreshResponseImpl.getInstance(response);
}
 
Example #24
Source File: ElasticSearchUtilImpl.java    From metacat with Apache License 2.0 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public void refresh() {
    client.admin().indices().refresh(new RefreshRequest(esIndex)).actionGet();
}
 
Example #25
Source File: ElasticsearchClient.java    From yacy_grid_mcp with GNU Lesser General Public License v2.1 4 votes vote down vote up
public void refresh(String indexName) {
    new RefreshRequest(indexName);
}
 
Example #26
Source File: AbstractClient.java    From Elasticsearch with Apache License 2.0 4 votes vote down vote up
@Override
public ActionFuture<RefreshResponse> refresh(final RefreshRequest request) {
    return execute(RefreshAction.INSTANCE, request);
}
 
Example #27
Source File: AbstractClient.java    From Elasticsearch with Apache License 2.0 4 votes vote down vote up
@Override
public void refresh(final RefreshRequest request, final ActionListener<RefreshResponse> listener) {
    execute(RefreshAction.INSTANCE, request, listener);
}
 
Example #28
Source File: ElasticsearchConnection.java    From foxtrot with Apache License 2.0 4 votes vote down vote up
public void refresh(final String index) {
    client.admin()
            .indices()
            .refresh(new RefreshRequest().indices(index))
            .actionGet();
}
 
Example #29
Source File: ElasticsearchTemplateRecordConsumerTest.java    From baleen with Apache License 2.0 4 votes vote down vote up
private void process() throws AnalysisEngineProcessException {
  analysisEngine.process(jCas);
  elasticsearch.client().admin().indices().refresh(new RefreshRequest(BALEEN_INDEX)).actionGet();
}
 
Example #30
Source File: BaseElasticSearchIndexBuilder.java    From sakai with Educational Community License v2.0 4 votes vote down vote up
/**
 * refresh the index from the current stored state {@inheritDoc}
 */
public void refreshIndex() {
    RefreshResponse response = client.admin().indices().refresh(new RefreshRequest(indexName)).actionGet();
}