本文整理汇总了Java中org.elasticsearch.action.admin.indices.get.GetIndexResponse类的典型用法代码示例。如果您正苦于以下问题:Java GetIndexResponse类的具体用法?Java GetIndexResponse怎么用?Java GetIndexResponse使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
GetIndexResponse类属于org.elasticsearch.action.admin.indices.get包,在下文中一共展示了GetIndexResponse类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testAutoCreateWithDisabledDynamicMappings
import org.elasticsearch.action.admin.indices.get.GetIndexResponse; //导入依赖的package包/类
public void testAutoCreateWithDisabledDynamicMappings() throws Exception {
assertAcked(client().admin().indices().preparePutTemplate("my_template")
.setCreate(true)
.setPatterns(Collections.singletonList("index_*"))
.addMapping("foo", "field", "type=keyword")
.setSettings(Settings.builder().put("index.mapper.dynamic", false).build())
.get());
// succeeds since 'foo' has an explicit mapping in the template
indexRandom(true, false, client().prepareIndex("index_1", "foo", "1").setSource("field", "abc"));
// fails since 'bar' does not have an explicit mapping in the template and dynamic template creation is disabled
TypeMissingException e1 = expectThrows(TypeMissingException.class,
() -> client().prepareIndex("index_2", "bar", "1").setSource("field", "abc").get());
assertEquals("type[bar] missing", e1.getMessage());
assertEquals("trying to auto create mapping, but dynamic mapping is disabled", e1.getCause().getMessage());
// make sure no mappings were created for bar
GetIndexResponse getIndexResponse = client().admin().indices().prepareGetIndex().addIndices("index_2").get();
assertFalse(getIndexResponse.mappings().containsKey("bar"));
}
示例2: getIndexNameForAlias
import org.elasticsearch.action.admin.indices.get.GetIndexResponse; //导入依赖的package包/类
/**
* Returns the real index name for a given alias.
* @param appid the index name (alias)
* @return the real index name (not alias)
*/
public static String getIndexNameForAlias(String appid) {
if (StringUtils.isBlank(appid)) {
return appid;
}
try {
GetIndexResponse result = getClient().admin().indices().prepareGetIndex().
setIndices(appid).execute().actionGet();
if (result.indices() != null && result.indices().length > 0) {
return result.indices()[0];
}
} catch (Exception e) {
logger.error(null, e);
}
return appid;
}
示例3: setup
import org.elasticsearch.action.admin.indices.get.GetIndexResponse; //导入依赖的package包/类
/**
* @param indices The names of all indices that will exist.
* @param mappings The index mappings.
* @return An object to test.
*/
public ElasticsearchColumnMetadataDao setup(
String[] indices,
ImmutableOpenMap<String, ImmutableOpenMap<String, MappingMetaData>> mappings) {
AdminClient adminClient = mock(AdminClient.class);
IndicesAdminClient indicesAdminClient = mock(IndicesAdminClient.class);
GetIndexRequestBuilder getIndexRequestBuilder = mock(GetIndexRequestBuilder.class);
GetIndexResponse getIndexResponse = mock(GetIndexResponse.class);
ActionFuture getMappingsActionFuture = mock(ActionFuture.class);
GetMappingsResponse getMappingsResponse = mock(GetMappingsResponse.class);
// setup the mocks so that a set of indices are available to the DAO
when(adminClient.indices()).thenReturn(indicesAdminClient);
when(indicesAdminClient.prepareGetIndex()).thenReturn(getIndexRequestBuilder);
when(getIndexRequestBuilder.setFeatures()).thenReturn(getIndexRequestBuilder);
when(getIndexRequestBuilder.get()).thenReturn(getIndexResponse);
when(getIndexResponse.getIndices()).thenReturn(indices);
// setup the mocks so that a set of mappings are available to the DAO
when(indicesAdminClient.getMappings(any())).thenReturn(getMappingsActionFuture);
when(getMappingsActionFuture.actionGet()).thenReturn(getMappingsResponse);
when(getMappingsResponse.getMappings()).thenReturn(mappings);
return new ElasticsearchColumnMetadataDao(adminClient);
}
示例4: testMissingIndicesQuery
import org.elasticsearch.action.admin.indices.get.GetIndexResponse; //导入依赖的package包/类
@SuppressWarnings("deprecation")
@Test
public void testMissingIndicesQuery() throws FoxtrotException {
List<Document> documents = TestUtils.getQueryDocumentsDifferentDate(getMapper(), new Date(2014 - 1900, 4, 1).getTime());
documents.addAll(TestUtils.getQueryDocumentsDifferentDate(getMapper(), new Date(2014 - 1900, 4, 5).getTime()));
getQueryStore().save(TestUtils.TEST_TABLE_NAME, documents);
for (Document document : documents) {
getElasticsearchServer().getClient().admin().indices()
.prepareRefresh(ElasticsearchUtils.getCurrentIndex(TestUtils.TEST_TABLE_NAME, document.getTimestamp()))
.setForce(true).execute().actionGet();
}
GetIndexResponse response = getElasticsearchServer().getClient().admin().indices().getIndex(new GetIndexRequest()).actionGet();
assertEquals(3, response.getIndices().length);
Query query = new Query();
query.setLimit(documents.size());
query.setTable(TestUtils.TEST_TABLE_NAME);
BetweenFilter betweenFilter = new BetweenFilter();
betweenFilter.setField("_timestamp");
betweenFilter.setFrom(documents.get(0).getTimestamp());
betweenFilter.setTo(documents.get(documents.size() - 1).getTimestamp());
betweenFilter.setTemporal(true);
query.setFilters(Lists.<Filter>newArrayList(betweenFilter));
QueryResponse actualResponse = QueryResponse.class.cast(getQueryExecutor().execute(query));
assertEquals(documents.size(), actualResponse.getDocuments().size());
}
示例5: assertIndexSanity
import org.elasticsearch.action.admin.indices.get.GetIndexResponse; //导入依赖的package包/类
private void assertIndexSanity(String index) {
GetIndexResponse getIndexResponse = client().admin().indices().prepareGetIndex().get();
assertEquals(1, getIndexResponse.indices().length);
assertEquals(index, getIndexResponse.indices()[0]);
ensureYellow(index);
SearchResponse test = client().prepareSearch(index).get();
assertThat(test.getHits().getTotalHits(), greaterThanOrEqualTo(1L));
}
示例6: buildResponse
import org.elasticsearch.action.admin.indices.get.GetIndexResponse; //导入依赖的package包/类
@Override
public RestResponse buildResponse(GetIndexResponse getIndexResponse, XContentBuilder builder) throws Exception {
GetIndexRequest.Feature[] features = getIndexRequest.features();
String[] indices = getIndexResponse.indices();
builder.startObject();
for (String index : indices) {
builder.startObject(index);
for (GetIndexRequest.Feature feature : features) {
switch (feature) {
case ALIASES:
writeAliases(getIndexResponse.aliases().get(index), builder, channel.request());
break;
case MAPPINGS:
writeMappings(getIndexResponse.mappings().get(index), builder, channel.request());
break;
case SETTINGS:
writeSettings(getIndexResponse.settings().get(index), builder, channel.request());
break;
default:
throw new IllegalStateException("feature [" + feature + "] is not valid");
}
}
builder.endObject();
}
builder.endObject();
return new BytesRestResponse(RestStatus.OK, builder);
}
示例7: showAll_atLeastOneIndexReturns
import org.elasticsearch.action.admin.indices.get.GetIndexResponse; //导入依赖的package包/类
@Test
public void showAll_atLeastOneIndexReturns() throws SqlParseException, SQLFeatureNotSupportedException, IOException {
String query = "show *";
GetIndexResponse getIndexResponse = runShowQuery(query);
ImmutableOpenMap<String, ImmutableOpenMap<String, MappingMetaData>> mappings = getIndexResponse.getMappings();
Assert.assertTrue(mappings.size() >= 1);
}
示例8: showIndex_onlyOneIndexReturn
import org.elasticsearch.action.admin.indices.get.GetIndexResponse; //导入依赖的package包/类
@Test
public void showIndex_onlyOneIndexReturn() throws SqlParseException, SQLFeatureNotSupportedException, IOException {
String query = "show "+ TEST_INDEX;
GetIndexResponse getIndexResponse = runShowQuery(query);
ImmutableOpenMap<String, ImmutableOpenMap<String, MappingMetaData>> mappings = getIndexResponse.getMappings();
Assert.assertEquals(1, mappings.size());
Assert.assertTrue(mappings.containsKey(TEST_INDEX));
}
示例9: showIndex_onlyOneIndexReturWithMoreThanOneTypes
import org.elasticsearch.action.admin.indices.get.GetIndexResponse; //导入依赖的package包/类
@Test
public void showIndex_onlyOneIndexReturWithMoreThanOneTypes() throws SqlParseException, SQLFeatureNotSupportedException, IOException {
String query = "show "+ TEST_INDEX;
GetIndexResponse getIndexResponse = runShowQuery(query);
ImmutableOpenMap<String, ImmutableOpenMap<String, MappingMetaData>> mappings = getIndexResponse.getMappings();
ImmutableOpenMap<String, MappingMetaData> typeToData = mappings.get(TEST_INDEX);
Assert.assertTrue(typeToData.size()>1);
}
示例10: showIndexType_onlyOneTypeReturn
import org.elasticsearch.action.admin.indices.get.GetIndexResponse; //导入依赖的package包/类
@Test
public void showIndexType_onlyOneTypeReturn() throws SqlParseException, SQLFeatureNotSupportedException, IOException {
String query = String.format("show %s/account", TEST_INDEX);
GetIndexResponse getIndexResponse = runShowQuery(query);
ImmutableOpenMap<String, ImmutableOpenMap<String, MappingMetaData>> mappings = getIndexResponse.getMappings();
ImmutableOpenMap<String, MappingMetaData> typeToData = mappings.get(TEST_INDEX);
Assert.assertEquals(1,typeToData.size());
}
示例11: assertESTypesExists
import org.elasticsearch.action.admin.indices.get.GetIndexResponse; //导入依赖的package包/类
/**
* Checks if KPI's elasticsearch Index and Type exists
*/
public KPIDataLoader assertESTypesExists()
{
final IndicesAdminClient admin = elasticsearchClient.admin()
.indices();
//
// Check index exists
final String esSearchIndex = kpi.getESSearchIndex();
final GetIndexResponse indexResponse = admin.prepareGetIndex()
.addIndices(esSearchIndex)
.get();
final List<String> indexesFound = Arrays.asList(indexResponse.getIndices());
if (!indexesFound.contains(esSearchIndex))
{
throw new AdempiereException("ES index '" + esSearchIndex + "' not found in " + indexesFound);
}
logger.debug("Indexes found: {}", indexesFound);
//
// Check type exists
final String esTypes = kpi.getESSearchTypes();
final boolean esTypesExists = admin.prepareTypesExists(esSearchIndex)
.setTypes(kpi.getESSearchTypes())
.get()
.isExists();
if (!esTypesExists)
{
throw new AdempiereException("Elasticseatch types " + esTypes + " does not exist");
}
// All good
return this;
}
示例12: getAllIndice
import org.elasticsearch.action.admin.indices.get.GetIndexResponse; //导入依赖的package包/类
private List<String> getAllIndice() {
final List<String> indice = new LinkedList<String>();
final GetIndexResponse resp = client.admin().indices().getIndex(new GetIndexRequest()).actionGet();
for (final String indexName : resp.indices()) {
if (indexName.startsWith(props.getEsSpanIndexPrefix()) //
|| indexName.startsWith(props.getEsAnnotationIndexPrefix())) {
indice.add(indexName);
}
}
return indice;
}
示例13: showIndex_onlyOneIndexReturn
import org.elasticsearch.action.admin.indices.get.GetIndexResponse; //导入依赖的package包/类
@Test
public void showIndex_onlyOneIndexReturn() throws SqlParseException, SQLFeatureNotSupportedException, IOException {
String query = "show "+ TestsConstants.TEST_INDEX;
GetIndexResponse getIndexResponse = runShowQuery(query);
ImmutableOpenMap<String, ImmutableOpenMap<String, MappingMetaData>> mappings = getIndexResponse.getMappings();
Assert.assertEquals(1, mappings.size());
Assert.assertTrue(mappings.containsKey(TestsConstants.TEST_INDEX));
}
示例14: showIndex_onlyOneIndexReturWithMoreThanOneTypes
import org.elasticsearch.action.admin.indices.get.GetIndexResponse; //导入依赖的package包/类
@Test
public void showIndex_onlyOneIndexReturWithMoreThanOneTypes() throws SqlParseException, SQLFeatureNotSupportedException, IOException {
String query = "show "+ TestsConstants.TEST_INDEX;
GetIndexResponse getIndexResponse = runShowQuery(query);
ImmutableOpenMap<String, ImmutableOpenMap<String, MappingMetaData>> mappings = getIndexResponse.getMappings();
ImmutableOpenMap<String, MappingMetaData> typeToData = mappings.get(TestsConstants.TEST_INDEX);
Assert.assertTrue(typeToData.size()>1);
}
示例15: showIndexType_onlyOneTypeReturn
import org.elasticsearch.action.admin.indices.get.GetIndexResponse; //导入依赖的package包/类
@Test
public void showIndexType_onlyOneTypeReturn() throws SqlParseException, SQLFeatureNotSupportedException, IOException {
String query = String.format("show %s/account", TestsConstants.TEST_INDEX);
GetIndexResponse getIndexResponse = runShowQuery(query);
ImmutableOpenMap<String, ImmutableOpenMap<String, MappingMetaData>> mappings = getIndexResponse.getMappings();
ImmutableOpenMap<String, MappingMetaData> typeToData = mappings.get(TestsConstants.TEST_INDEX);
Assert.assertEquals(1,typeToData.size());
}