Search in sources :

Example 51 with IndexService

use of org.elasticsearch.index.IndexService in project elasticsearch by elastic.

the class MultiMatchQueryTests method setup.

@Before
public void setup() throws IOException {
    Settings settings = Settings.builder().put("index.analysis.filter.syns.type", "synonym").putArray("index.analysis.filter.syns.synonyms", "quick,fast").put("index.analysis.analyzer.syns.tokenizer", "standard").put("index.analysis.analyzer.syns.filter", "syns").build();
    IndexService indexService = createIndex("test", settings);
    MapperService mapperService = indexService.mapperService();
    String mapping = "{\n" + "    \"person\":{\n" + "        \"properties\":{\n" + "            \"name\":{\n" + "                  \"properties\":{\n" + "                        \"first\": {\n" + "                            \"type\":\"text\",\n" + "                            \"analyzer\":\"syns\"\n" + "                        }," + "                        \"last\": {\n" + "                            \"type\":\"text\",\n" + "                            \"analyzer\":\"syns\"\n" + "                        }" + "                   }" + "            }\n" + "        }\n" + "    }\n" + "}";
    mapperService.merge("person", new CompressedXContent(mapping), MapperService.MergeReason.MAPPING_UPDATE, false);
    this.indexService = indexService;
}
Also used : IndexService(org.elasticsearch.index.IndexService) CompressedXContent(org.elasticsearch.common.compress.CompressedXContent) Settings(org.elasticsearch.common.settings.Settings) MapperService(org.elasticsearch.index.mapper.MapperService) Before(org.junit.Before)

Example 52 with IndexService

use of org.elasticsearch.index.IndexService in project elasticsearch by elastic.

the class RangeQueryRewriteTests method testRewriteMissingField.

public void testRewriteMissingField() throws Exception {
    IndexService indexService = createIndex("test");
    IndexReader reader = new MultiReader();
    QueryRewriteContext context = new QueryShardContext(0, indexService.getIndexSettings(), null, null, indexService.mapperService(), null, null, xContentRegistry(), null, reader, null);
    RangeQueryBuilder range = new RangeQueryBuilder("foo");
    assertEquals(Relation.DISJOINT, range.getRelation(context));
}
Also used : IndexService(org.elasticsearch.index.IndexService) MultiReader(org.apache.lucene.index.MultiReader) IndexReader(org.apache.lucene.index.IndexReader)

Example 53 with IndexService

use of org.elasticsearch.index.IndexService in project elasticsearch by elastic.

the class GlobalCheckpointSyncActionTests method testTranslogSyncAfterGlobalCheckpointSync.

public void testTranslogSyncAfterGlobalCheckpointSync() throws Exception {
    final IndicesService indicesService = mock(IndicesService.class);
    final Index index = new Index("index", "uuid");
    final IndexService indexService = mock(IndexService.class);
    when(indicesService.indexServiceSafe(index)).thenReturn(indexService);
    final int id = randomIntBetween(0, 4);
    final IndexShard indexShard = mock(IndexShard.class);
    when(indexService.getShard(id)).thenReturn(indexShard);
    final Translog translog = mock(Translog.class);
    when(indexShard.getTranslog()).thenReturn(translog);
    final GlobalCheckpointSyncAction action = new GlobalCheckpointSyncAction(Settings.EMPTY, transportService, clusterService, indicesService, threadPool, shardStateAction, new ActionFilters(Collections.emptySet()), new IndexNameExpressionResolver(Settings.EMPTY));
    final ShardId shardId = new ShardId(index, id);
    final GlobalCheckpointSyncAction.PrimaryRequest primaryRequest = new GlobalCheckpointSyncAction.PrimaryRequest(shardId);
    if (randomBoolean()) {
        action.shardOperationOnPrimary(primaryRequest, indexShard);
    } else {
        action.shardOperationOnReplica(new GlobalCheckpointSyncAction.ReplicaRequest(primaryRequest, randomNonNegativeLong()), indexShard);
    }
    verify(translog).sync();
}
Also used : IndexService(org.elasticsearch.index.IndexService) IndexShard(org.elasticsearch.index.shard.IndexShard) IndicesService(org.elasticsearch.indices.IndicesService) Index(org.elasticsearch.index.Index) ActionFilters(org.elasticsearch.action.support.ActionFilters) Translog(org.elasticsearch.index.translog.Translog) ShardId(org.elasticsearch.index.shard.ShardId) IndexNameExpressionResolver(org.elasticsearch.cluster.metadata.IndexNameExpressionResolver)

Example 54 with IndexService

use of org.elasticsearch.index.IndexService in project elasticsearch by elastic.

the class IndexShardIT method testStressMaybeFlush.

public void testStressMaybeFlush() throws Exception {
    createIndex("test");
    ensureGreen();
    IndicesService indicesService = getInstanceFromNode(IndicesService.class);
    IndexService test = indicesService.indexService(resolveIndex("test"));
    final IndexShard shard = test.getShardOrNull(0);
    assertFalse(shard.shouldFlush());
    client().admin().indices().prepareUpdateSettings("test").setSettings(Settings.builder().put(IndexSettings.INDEX_TRANSLOG_FLUSH_THRESHOLD_SIZE_SETTING.getKey(), new ByteSizeValue(117, /* size of the operation + header&footer*/
    ByteSizeUnit.BYTES)).build()).get();
    client().prepareIndex("test", "test", "0").setSource("{}", XContentType.JSON).setRefreshPolicy(randomBoolean() ? IMMEDIATE : NONE).get();
    assertFalse(shard.shouldFlush());
    final AtomicBoolean running = new AtomicBoolean(true);
    final int numThreads = randomIntBetween(2, 4);
    Thread[] threads = new Thread[numThreads];
    CyclicBarrier barrier = new CyclicBarrier(numThreads + 1);
    for (int i = 0; i < threads.length; i++) {
        threads[i] = new Thread() {

            @Override
            public void run() {
                try {
                    barrier.await();
                } catch (InterruptedException | BrokenBarrierException e) {
                    throw new RuntimeException(e);
                }
                while (running.get()) {
                    shard.maybeFlush();
                }
            }
        };
        threads[i].start();
    }
    barrier.await();
    FlushStats flushStats = shard.flushStats();
    long total = flushStats.getTotal();
    client().prepareIndex("test", "test", "1").setSource("{}", XContentType.JSON).get();
    assertBusy(() -> assertEquals(total + 1, shard.flushStats().getTotal()));
    running.set(false);
    for (int i = 0; i < threads.length; i++) {
        threads[i].join();
    }
    assertEquals(total + 1, shard.flushStats().getTotal());
}
Also used : IndexService(org.elasticsearch.index.IndexService) ByteSizeValue(org.elasticsearch.common.unit.ByteSizeValue) IndicesService(org.elasticsearch.indices.IndicesService) CyclicBarrier(java.util.concurrent.CyclicBarrier) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) FlushStats(org.elasticsearch.index.flush.FlushStats)

Example 55 with IndexService

use of org.elasticsearch.index.IndexService in project elasticsearch by elastic.

the class IndexShardIT method testUpdatePriority.

public void testUpdatePriority() {
    assertAcked(client().admin().indices().prepareCreate("test").setSettings(IndexMetaData.SETTING_PRIORITY, 200));
    IndexService indexService = getInstanceFromNode(IndicesService.class).indexService(resolveIndex("test"));
    assertEquals(200, indexService.getIndexSettings().getSettings().getAsInt(IndexMetaData.SETTING_PRIORITY, 0).intValue());
    client().admin().indices().prepareUpdateSettings("test").setSettings(Settings.builder().put(IndexMetaData.SETTING_PRIORITY, 400).build()).get();
    assertEquals(400, indexService.getIndexSettings().getSettings().getAsInt(IndexMetaData.SETTING_PRIORITY, 0).intValue());
}
Also used : IndexService(org.elasticsearch.index.IndexService) IndicesService(org.elasticsearch.indices.IndicesService)

Aggregations

IndexService (org.elasticsearch.index.IndexService)173 IndexShard (org.elasticsearch.index.shard.IndexShard)53 CompressedXContent (org.elasticsearch.common.compress.CompressedXContent)49 IndicesService (org.elasticsearch.indices.IndicesService)38 DocumentMapper (org.elasticsearch.index.mapper.DocumentMapper)30 Settings (org.elasticsearch.common.settings.Settings)25 ShardId (org.elasticsearch.index.shard.ShardId)24 Index (org.elasticsearch.index.Index)20 QueryShardContext (org.elasticsearch.index.query.QueryShardContext)17 ShardRouting (org.elasticsearch.cluster.routing.ShardRouting)16 IOException (java.io.IOException)15 HashMap (java.util.HashMap)15 ArrayList (java.util.ArrayList)14 ClusterState (org.elasticsearch.cluster.ClusterState)13 Map (java.util.Map)12 ClusterService (org.elasticsearch.cluster.service.ClusterService)12 ElasticsearchException (org.elasticsearch.ElasticsearchException)11 IndexMetaData (org.elasticsearch.cluster.metadata.IndexMetaData)11 ParsedDocument (org.elasticsearch.index.mapper.ParsedDocument)11 List (java.util.List)10