public void testAutoBoost() throws Exception {
   for (boolean boost : new boolean[] {false, true}) {
     String index = "test_" + boost;
     IndexService indexService =
         createIndex(
             index,
             client()
                 .admin()
                 .indices()
                 .prepareCreate(index)
                 .addMapping("type", "foo", "type=string" + (boost ? ",boost=2" : "")));
     client().prepareIndex(index, "type").setSource("foo", "bar").get();
     client().admin().indices().prepareRefresh(index).get();
     Query query =
         indexService
             .mapperService()
             .documentMapper("type")
             .allFieldMapper()
             .fieldType()
             .termQuery("bar", null);
     try (Searcher searcher = indexService.getShardOrNull(0).acquireSearcher("tests")) {
       query = searcher.searcher().rewrite(query);
       final Class<?> expected = boost ? AllTermQuery.class : TermQuery.class;
       assertThat(query, Matchers.instanceOf(expected));
     }
   }
 }
Пример #2
0
 @Override
 public void onRemoval(ShardId shardId, String fieldName, boolean wasEvicted, long sizeInBytes) {
   if (shardId != null) {
     final IndexShard shard = indexService.getShardOrNull(shardId.id());
     if (shard != null) {
       shard.fieldData().onRemoval(shardId, fieldName, wasEvicted, sizeInBytes);
     }
   }
 }
Пример #3
0
 @Override
 public void onCache(ShardId shardId, String fieldName, Accountable ramUsage) {
   if (shardId != null) {
     final IndexShard shard = indexService.getShardOrNull(shardId.id());
     if (shard != null) {
       shard.fieldData().onCache(shardId, fieldName, ramUsage);
     }
   }
 }
Пример #4
0
 @Override
 public void onRemoval(ShardId shardId, Accountable accountable) {
   if (shardId != null) {
     final IndexShard shard = indexService.getShardOrNull(shardId.id());
     if (shard != null) {
       long ramBytesUsed = accountable != null ? accountable.ramBytesUsed() : 0L;
       shard.shardBitsetFilterCache().onRemoval(ramBytesUsed);
     }
   }
 }
 private void failReplicaIfNeeded(String index, int shardId, Throwable t) {
   logger.trace("failure on replica [{}][{}]", t, index, shardId);
   if (ignoreReplicaException(t) == false) {
     IndexService indexService = indicesService.indexService(index);
     if (indexService == null) {
       logger.debug(
           "ignoring failed replica [{}][{}] because index was already removed.", index, shardId);
       return;
     }
     IndexShard indexShard = indexService.getShardOrNull(shardId);
     if (indexShard == null) {
       logger.debug(
           "ignoring failed replica [{}][{}] because index was already removed.", index, shardId);
       return;
     }
     indexShard.failShard(actionName + " failed on replica", t);
   }
 }