org.elasticsearch.action.admin.indices.settings.get.GetSettingsResponse Java Examples

The following examples show how to use org.elasticsearch.action.admin.indices.settings.get.GetSettingsResponse. 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: RestGetSettingsAction.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) {
    final String[] names = request.paramAsStringArrayOrEmptyIfAll("name");
    GetSettingsRequest getSettingsRequest = new GetSettingsRequest()
            .indices(Strings.splitStringByCommaToArray(request.param("index")))
            .indicesOptions(IndicesOptions.fromRequest(request, IndicesOptions.strictExpandOpen()))
            .humanReadable(request.hasParam("human"))
            .names(names);
    getSettingsRequest.local(request.paramAsBoolean("local", getSettingsRequest.local()));

    client.admin().indices().getSettings(getSettingsRequest, new RestBuilderListener<GetSettingsResponse>(channel) {

        @Override
        public RestResponse buildResponse(GetSettingsResponse getSettingsResponse, XContentBuilder builder) throws Exception {
            builder.startObject();
            for (ObjectObjectCursor<String, Settings> cursor : getSettingsResponse.getIndexToSettings()) {
                // no settings, jump over it to shorten the response data
                if (cursor.value.getAsMap().isEmpty()) {
                    continue;
                }
                builder.startObject(cursor.key, XContentBuilder.FieldCaseConversion.NONE);
                builder.startObject(Fields.SETTINGS);
                cursor.value.toXContent(builder, request);
                builder.endObject();
                builder.endObject();
            }
            builder.endObject();
            return new BytesRestResponse(OK, builder);
        }
    });
}
 
Example #2
Source File: ElasticSearchConfigTest.java    From titan1withtp3.1 with Apache License 2.0 5 votes vote down vote up
@Test
public void testIndexCreationOptions() throws InterruptedException, BackendException {
    final int shards = 77;

    ElasticsearchRunner esr = new ElasticsearchRunner(".", "indexCreationOptions.yml");
    esr.start();
    CommonsConfiguration cc = new CommonsConfiguration(new BaseConfiguration());
    cc.set("index." + INDEX_NAME + ".elasticsearch.create.ext.number_of_shards", String.valueOf(shards));
    cc.set("index." + INDEX_NAME + ".elasticsearch.ext.cluster.name", "indexCreationOptions");
    ModifiableConfiguration config =
            new ModifiableConfiguration(GraphDatabaseConfiguration.ROOT_NS,
                    cc, BasicConfiguration.Restriction.NONE);
    config.set(INTERFACE, ElasticSearchSetup.NODE.toString(), INDEX_NAME);
    Configuration indexConfig = config.restrictTo(INDEX_NAME);
    IndexProvider idx = new ElasticSearchIndex(indexConfig);
    simpleWriteAndQuery(idx);



    ImmutableSettings.Builder settingsBuilder = ImmutableSettings.settingsBuilder();
    settingsBuilder.put("discovery.zen.ping.multicast.enabled", "false");
    settingsBuilder.put("discovery.zen.ping.unicast.hosts", "localhost,127.0.0.1:9300");
    settingsBuilder.put("cluster.name", "indexCreationOptions");
    NodeBuilder nodeBuilder = NodeBuilder.nodeBuilder().settings(settingsBuilder.build());
    nodeBuilder.client(true).data(false).local(false);
    Node n = nodeBuilder.build().start();

    GetSettingsResponse response = n.client().admin().indices().getSettings(new GetSettingsRequest().indices("titan")).actionGet();
    assertEquals(String.valueOf(shards), response.getSetting("titan", "index.number_of_shards"));

    idx.close();
    n.stop();
    esr.stop();
}
 
Example #3
Source File: QueryComponent.java    From elasticsearch-reindex-tool with Apache License 2.0 5 votes vote down vote up
public SearchResponse prepareSearchScrollRequest() {
  // find out how many indices and shards are affected by this query to not get huge result sets when there are very many indices affected by the name, e.g. when wildcards are used
  // otherwise we regularly run into OOMs when a query goes against a large number of indices
  // I did not find a better way to find out the number of shards than to query a list of indices and for each index query the number of shards via the settings
  GetSettingsResponse getSettingsResponse = client.admin().indices().getSettings(new GetSettingsRequest().indices(dataPointer.getIndexName())).actionGet();
  int numShards = 0, numIndices = 0;
  for(ObjectCursor<Settings> settings : getSettingsResponse.getIndexToSettings().values()) {
    numShards += settings.value.getAsInt("index.number_of_shards", 0);
    numIndices++;
  }

  int sizePerShard = (int)Math.ceil((double)SCROLL_SHARD_LIMIT/numShards);
  logger.info("Found " + numIndices + " indices and " + numShards + " shards matching the index-pattern, thus setting the sizePerShard to " + sizePerShard);

  SearchRequestBuilder searchRequestBuilder = client.prepareSearch(dataPointer.getIndexName())
      .setTypes(dataPointer.getTypeName())
      .setSearchType(SearchType.SCAN)
      .addFields("_ttl", "_source")
      .setScroll(new TimeValue(SCROLL_TIME_LIMIT))
      .setSize(sizePerShard);

  if (!Strings.isNullOrEmpty(query.getQuery())) {
    searchRequestBuilder.setQuery(query.getQuery());
  }
  if (!Strings.isNullOrEmpty(query.getSortField())) {
    searchRequestBuilder.addSort(new FieldSortBuilder(query.getSortField()).order(query.getSortOrder()));
  }

  bound.map(resolvedBound -> boundedFilterFactory.createBoundedFilter(segmentationField.get(), resolvedBound))
      .ifPresent(searchRequestBuilder::setQuery);

  return searchRequestBuilder.execute().actionGet();
}
 
Example #4
Source File: QueryComponentTest.java    From elasticsearch-reindex-tool with Apache License 2.0 5 votes vote down vote up
@Test
public void testElasticsearchReplicaHandlingInScrolls() {
  // given
  indexWithSampleData(200);
  ElasticDataPointer sourceDataPointer = embeddedElasticsearchCluster.createDataPointer(SOURCE_INDEX);
  Client sourceClient = ElasticSearchClientFactory.createClient(sourceDataPointer);

  GetSettingsResponse indexSettings = sourceClient.admin().indices().getSettings(new GetSettingsRequest().indices(SOURCE_INDEX)).actionGet();
  assertEquals("We should have an index with 5 shards now",
          "5", indexSettings.getIndexToSettings().get(SOURCE_INDEX).get("index.number_of_shards"));
  assertEquals("We should have an index with one replica now",
          "1", indexSettings.getIndexToSettings().get(SOURCE_INDEX).get("index.number_of_replicas"));

  // when
  SearchRequestBuilder searchRequestBuilder = sourceClient.prepareSearch(sourceDataPointer.getIndexName())
          .setTypes(DATA_TYPE)
          .setSearchType(SearchType.SCAN)
          .addFields("_ttl", "_source")
          .setScroll(new TimeValue(QueryComponent.SCROLL_TIME_LIMIT))
          .setSize(10);
  assertNotNull(searchRequestBuilder);

  // then
  SearchResponse searchResponse = searchRequestBuilder.execute().actionGet();
  assertEquals("Overall there should be 200 hits",
          200L, searchResponse.getHits().getTotalHits());
  assertEquals("Initially zero documents are loaded",
          0L, searchResponse.getHits().getHits().length);

  // when
  searchResponse = sourceClient.prepareSearchScroll(searchResponse.getScrollId())
          .setScroll(new TimeValue(QueryComponent.SCROLL_TIMEOUT))
          .get();

  // then
  assertEquals(200L, searchResponse.getHits().getTotalHits());
  assertEquals(50L, searchResponse.getHits().getHits().length);
}
 
Example #5
Source File: ElasticSearchUtils.java    From bdt with Apache License 2.0 5 votes vote down vote up
/**
 * Get Index Setting
 *
 * @param indexName
 * @param settingName
 * @return string with index setting
 */

public String getElasticsearchIndexSetting(String indexName, String settingName) {

    try {
        GetSettingsRequest request = new GetSettingsRequest().indices(indexName).names(settingName).includeDefaults(true);
        GetSettingsResponse settingsResponse = client.indices().getSettings(request, RequestOptions.DEFAULT);

        return settingsResponse.getSetting(indexName, settingName);
    } catch (IOException e) {
        throw new ElasticsearchException("Error getting setting " + settingName + "from index " + indexName);
    }
}
 
Example #6
Source File: AbstractClient.java    From Elasticsearch with Apache License 2.0 4 votes vote down vote up
@Override
public ActionFuture<GetSettingsResponse> getSettings(GetSettingsRequest request) {
    return execute(GetSettingsAction.INSTANCE, request);
}
 
Example #7
Source File: AbstractClient.java    From Elasticsearch with Apache License 2.0 4 votes vote down vote up
@Override
public void getSettings(GetSettingsRequest request, ActionListener<GetSettingsResponse> listener) {
    execute(GetSettingsAction.INSTANCE, request, listener);
}
 
Example #8
Source File: CrudDemo.java    From javabase with Apache License 2.0 4 votes vote down vote up
private static void showIndexSettings(IndicesAdminClient indicesAdminClient, String indexName) {
        GetSettingsResponse settingInfo = indicesAdminClient.getSettings(new GetSettingsRequest().indices(indexName)).actionGet();
//        log.info("显示 index setting:{}", settingInfo.getIndexToSettings().get(indexName).getAsMap());
    }
 
Example #9
Source File: QueryComponentTest.java    From elasticsearch-reindex-tool with Apache License 2.0 4 votes vote down vote up
@Test
public void testQueryWithData() {
  // given
  indexWithSampleData(7000);
  ElasticDataPointer sourceDataPointer = embeddedElasticsearchCluster.createDataPointer(SOURCE_INDEX);
  Client sourceClient = ElasticSearchClientFactory.createClient(sourceDataPointer);
  ElasticSearchQuery elasticSearchQuery = embeddedElasticsearchCluster.createInitialQuery("");

  GetSettingsResponse indexSettings = sourceClient.admin().indices().getSettings(new GetSettingsRequest().indices(SOURCE_INDEX)).actionGet();
  assertEquals("We should have an index with 5 shards now",
          "5", indexSettings.getIndexToSettings().get(SOURCE_INDEX).get("index.number_of_shards"));
  assertEquals("We should have an index with one replica now",
          "1", indexSettings.getIndexToSettings().get(SOURCE_INDEX).get("index.number_of_replicas"));

  // when
  QueryComponent component = QueryComponentBuilder.builder()
          .setClient(sourceClient)
          .setDataPointer(sourceDataPointer)
          .setQuery(elasticSearchQuery)
          .createQueryComponent();
  SearchResponse searchResponse = component.prepareSearchScrollRequest();

  // then
  assertEquals("Overall there should be 7000 hits",
          7000L, searchResponse.getHits().getTotalHits());
  assertEquals("Initially zero documents are loaded",
          0L, searchResponse.getHits().getHits().length);
  assertEquals("Initially zero documents are loaded",
          0L, component.getResponseSize(searchResponse));
  assertTrue("Some documents are found",
          component.searchResultsNotEmpty(searchResponse));

  // when
  searchResponse = component.getNextScrolledSearchResults(searchResponse.getScrollId());

  // then
  assertEquals("Overall there should be 7000 hits",
          7000L, searchResponse.getHits().getTotalHits());
  assertEquals("QueryComponent tries to compute the hits to be 5000 on evenly distributed documents, never more!",
          5000L, searchResponse.getHits().getHits().length);
  assertEquals("QueryComponent tries to compute the hits to be 5000 on evenly distributed documents, never more!",
          5000L, component.getResponseSize(searchResponse));
  assertTrue("Some documents are found",
          component.searchResultsNotEmpty(searchResponse));
}
 
Example #10
Source File: IndicesAdminClient.java    From Elasticsearch with Apache License 2.0 2 votes vote down vote up
/**
 * Executed a per index settings get request and returns the settings for the indices specified.
 * Note: this is a per index request and will not include settings that are set on the cluster
 * level. This request is not exhaustive, it will not return default values for setting.
 */
void getSettings(GetSettingsRequest request, ActionListener<GetSettingsResponse> listener);
 
Example #11
Source File: IndicesAdminClient.java    From Elasticsearch with Apache License 2.0 2 votes vote down vote up
/**
 * Executed a per index settings get request.
 * @see #getSettings(org.elasticsearch.action.admin.indices.settings.get.GetSettingsRequest)
 */
ActionFuture<GetSettingsResponse> getSettings(GetSettingsRequest request);