本文整理匯總了Java中org.elasticsearch.action.search.SearchResponse.getFailedShards方法的典型用法代碼示例。如果您正苦於以下問題:Java SearchResponse.getFailedShards方法的具體用法?Java SearchResponse.getFailedShards怎麽用?Java SearchResponse.getFailedShards使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.elasticsearch.action.search.SearchResponse
的用法示例。
在下文中一共展示了SearchResponse.getFailedShards方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: check
import org.elasticsearch.action.search.SearchResponse; //導入方法依賴的package包/類
static void check(SearchResponse response) {
if (response.status() != RestStatus.OK) {
throw new StarGraphException("ES failure. RestStatus is " + response.status());
}
if (response.getFailedShards() > 0) {
throw new StarGraphException("Shard Search Failure.");
}
}
示例2: formatShardStatus
import org.elasticsearch.action.search.SearchResponse; //導入方法依賴的package包/類
public static String formatShardStatus(SearchResponse response) {
String msg = " Total shards: " + response.getTotalShards() + " Successful shards: " + response.getSuccessfulShards() + " & "
+ response.getFailedShards() + " shard failures:";
for (ShardSearchFailure failure : response.getShardFailures()) {
msg += "\n " + failure.toString();
}
return msg;
}
示例3: testSimpleIndexTemplateTests
import org.elasticsearch.action.search.SearchResponse; //導入方法依賴的package包/類
public void testSimpleIndexTemplateTests() throws Exception {
// clean all templates setup by the framework.
client().admin().indices().prepareDeleteTemplate("*").get();
// check get all templates on an empty index.
GetIndexTemplatesResponse response = client().admin().indices().prepareGetTemplates().get();
assertThat(response.getIndexTemplates(), empty());
client().admin().indices().preparePutTemplate("template_1")
.setPatterns(Collections.singletonList("te*"))
.setSettings(indexSettings())
.setOrder(0)
.addMapping("type1", XContentFactory.jsonBuilder().startObject().startObject("type1").startObject("properties")
.startObject("field1").field("type", "text").field("store", true).endObject()
.startObject("field2").field("type", "keyword").field("store", true).endObject()
.endObject().endObject().endObject())
.get();
client().admin().indices().preparePutTemplate("template_2")
.setPatterns(Collections.singletonList("test*"))
.setSettings(indexSettings())
.setOrder(1)
.addMapping("type1", XContentFactory.jsonBuilder().startObject().startObject("type1").startObject("properties")
.startObject("field2").field("type", "text").field("store", false).endObject()
.endObject().endObject().endObject())
.get();
// test create param
assertThrows(client().admin().indices().preparePutTemplate("template_2")
.setPatterns(Collections.singletonList("test*"))
.setSettings(indexSettings())
.setCreate(true)
.setOrder(1)
.addMapping("type1", XContentFactory.jsonBuilder().startObject().startObject("type1").startObject("properties")
.startObject("field2").field("type", "text").field("store", false).endObject()
.endObject().endObject().endObject())
, IllegalArgumentException.class
);
response = client().admin().indices().prepareGetTemplates().get();
assertThat(response.getIndexTemplates(), hasSize(2));
// index something into test_index, will match on both templates
client().prepareIndex("test_index", "type1", "1")
.setSource("field1", "value1", "field2", "value 2")
.setRefreshPolicy(IMMEDIATE).get();
ensureGreen();
SearchResponse searchResponse = client().prepareSearch("test_index")
.setQuery(termQuery("field1", "value1"))
.addStoredField("field1").addStoredField("field2")
.execute().actionGet();
assertHitCount(searchResponse, 1);
assertThat(searchResponse.getHits().getAt(0).field("field1").getValue().toString(), equalTo("value1"));
// field2 is not stored.
assertThat(searchResponse.getHits().getAt(0).field("field2"), nullValue());
client().prepareIndex("text_index", "type1", "1")
.setSource("field1", "value1", "field2", "value 2")
.setRefreshPolicy(IMMEDIATE).get();
ensureGreen();
// now only match on one template (template_1)
searchResponse = client().prepareSearch("text_index")
.setQuery(termQuery("field1", "value1"))
.addStoredField("field1").addStoredField("field2")
.execute().actionGet();
if (searchResponse.getFailedShards() > 0) {
logger.warn("failed search {}", Arrays.toString(searchResponse.getShardFailures()));
}
assertHitCount(searchResponse, 1);
assertThat(searchResponse.getHits().getAt(0).field("field1").getValue().toString(), equalTo("value1"));
assertThat(searchResponse.getHits().getAt(0).field("field2").getValue().toString(), equalTo("value 2"));
}
示例4: CountResponse
import org.elasticsearch.action.search.SearchResponse; //導入方法依賴的package包/類
public CountResponse(SearchResponse searchResponse) {
super(searchResponse.getTotalShards(), searchResponse.getSuccessfulShards(), searchResponse.getFailedShards(), Arrays.asList(searchResponse.getShardFailures()));
this.count = searchResponse.getHits().totalHits();
this.terminatedEarly = searchResponse.isTerminatedEarly() != null && searchResponse.isTerminatedEarly();
}