use of org.opensearch.action.admin.indices.get.GetIndexResponse in project fesen-httpclient by codelibs.
the class Elasticsearch7ClientTest method test_get_index.
@Test
void test_get_index() throws Exception {
final String index = "test_get_index";
final String alias = "test_alias";
final XContentBuilder mappingBuilder = //
XContentFactory.jsonBuilder().startObject().startObject(//
"properties").startObject(//
"test_prop").field("type", //
"text").endObject().endObject().endObject();
final String source = BytesReference.bytes(mappingBuilder).utf8ToString();
CountDownLatch latch = new CountDownLatch(1);
client.admin().indices().prepareCreate(index).execute().actionGet();
client.admin().indices().prepareAliases().addAlias(index, alias).execute().actionGet();
client.admin().indices().preparePutMapping(index).setSource(source, XContentType.JSON).execute().actionGet();
client.admin().indices().prepareGetIndex().addIndices(index).execute(wrap(res -> {
assertEquals(index, res.getIndices()[0]);
assertTrue(res.getAliases().containsKey(index));
assertTrue(res.getMappings().containsKey(index));
assertTrue(res.getSettings().containsKey(index));
latch.countDown();
}, e -> {
e.printStackTrace();
try {
fail();
} finally {
latch.countDown();
}
}));
latch.await();
{
GetIndexResponse getIndexResponse = client.admin().indices().prepareGetIndex().addIndices(index).execute().actionGet();
assertEquals(index, getIndexResponse.getIndices()[0]);
assertTrue(getIndexResponse.getAliases().containsKey(index));
assertTrue(getIndexResponse.getMappings().containsKey(index));
assertTrue(getIndexResponse.getSettings().containsKey(index));
}
}
use of org.opensearch.action.admin.indices.get.GetIndexResponse in project fesen-httpclient by codelibs.
the class HttpGetIndexAction method execute.
public void execute(final GetIndexRequest request, final ActionListener<GetIndexResponse> listener) {
getCurlRequest(request).execute(response -> {
try (final XContentParser parser = createParser(response)) {
final GetIndexResponse getIndexResponse = GetIndexResponse.fromXContent(parser);
listener.onResponse(getIndexResponse);
} catch (final Exception e) {
listener.onFailure(toOpenSearchException(response, e));
}
}, e -> unwrapOpenSearchException(listener, e));
}
use of org.opensearch.action.admin.indices.get.GetIndexResponse in project fess-suggest by codelibs.
the class SuggesterTest method test_switchIndex.
@Test
public void test_switchIndex() throws Exception {
SuggestItem[] items = getItemSet1();
suggester.indexer().index(items);
suggester.refresh();
SuggestResponse response = suggester.suggest().setQuery("kensaku").setSuggestDetail(true).execute().getResponse();
assertEquals(1, response.getNum());
assertEquals("検索 エンジン", response.getWords().get(0));
SuggestResponse response2 = suggester.suggest().setSuggestDetail(true).execute().getResponse();
assertEquals(2, response2.getNum());
Thread.sleep(1000);
suggester.createNextIndex();
SuggestItem[] items2 = getItemSet2();
suggester.indexer().index(items2);
suggester.refresh();
response = suggester.suggest().setQuery("kensaku").setSuggestDetail(true).execute().getResponse();
assertEquals(1, response.getNum());
assertEquals("検索 エンジン", response.getWords().get(0));
response2 = suggester.suggest().setSuggestDetail(true).execute().getResponse();
assertEquals(2, response2.getNum());
suggester.switchIndex();
response = suggester.suggest().setQuery("kensaku").setSuggestDetail(true).execute().getResponse();
assertEquals(0, response.getNum());
response = suggester.suggest().setSuggestDetail(true).execute().getResponse();
assertEquals(3, response.getNum());
response2 = suggester.suggest().setQuery("-a").setSuggestDetail(true).execute().getResponse();
assertEquals(2, response2.getNum());
SuggestResponse response3 = suggester.suggest().setQuery("-aa-").setSuggestDetail(true).execute().getResponse();
assertEquals(1, response3.getNum());
GetIndexResponse getIndexResponse = runner.client().admin().indices().prepareGetIndex().execute().actionGet();
int count = 0;
for (String index : getIndexResponse.getIndices()) {
if (index.startsWith(suggester.getIndex())) {
count++;
}
}
assertEquals(2, count);
suggester.removeDisableIndices();
response = suggester.suggest().setSuggestDetail(true).execute().getResponse();
assertEquals(3, response.getNum());
getIndexResponse = runner.client().admin().indices().prepareGetIndex().execute().actionGet();
count = 0;
for (String index : getIndexResponse.getIndices()) {
if (index.startsWith(suggester.getIndex())) {
count++;
}
}
assertEquals(1, count);
}
use of org.opensearch.action.admin.indices.get.GetIndexResponse in project fess-suggest by codelibs.
the class Suggester method removeDisableIndices.
public void removeDisableIndices() {
final GetIndexResponse response = client.admin().indices().prepareGetIndex().addIndices("*").execute().actionGet(suggestSettings.getIndicesTimeout());
Stream.of(response.getIndices()).filter(s -> {
if (!isSuggestIndex(s)) {
return false;
}
final List<AliasMetadata> list = response.getAliases().get(s);
if (list == null) {
return true;
}
return list.isEmpty();
}).forEach(s -> {
if (logger.isInfoEnabled()) {
logger.info("Delete index: {}", s);
}
client.admin().indices().prepareDelete(s).execute().actionGet(suggestSettings.getIndicesTimeout());
});
}
use of org.opensearch.action.admin.indices.get.GetIndexResponse in project OpenSearch by opensearch-project.
the class OpenSearchIntegTestCase method resolveCustomDataPath.
public static String resolveCustomDataPath(String index) {
GetIndexResponse getIndexResponse = client().admin().indices().prepareGetIndex().setIndices(index).get();
assertTrue("index " + index + " not found", getIndexResponse.getSettings().containsKey(index));
return getIndexResponse.getSettings().get(index).get(IndexMetadata.SETTING_DATA_PATH);
}
Aggregations