Java 类org.elasticsearch.common.settings.Settings 实例源码

项目:elasticsearch_my    文件:TransportNodesAction.java   
protected TransportNodesAction(Settings settings, String actionName, ThreadPool threadPool,
                               ClusterService clusterService, TransportService transportService, ActionFilters actionFilters,
                               IndexNameExpressionResolver indexNameExpressionResolver,
                               Supplier<NodesRequest> request, Supplier<NodeRequest> nodeRequest,
                               String nodeExecutor,
                               Class<NodeResponse> nodeResponseClass) {
    super(settings, actionName, threadPool, transportService, actionFilters, indexNameExpressionResolver, request);
    this.clusterService = Objects.requireNonNull(clusterService);
    this.transportService = Objects.requireNonNull(transportService);
    this.nodeResponseClass = Objects.requireNonNull(nodeResponseClass);

    this.transportNodeAction = actionName + "[n]";

    transportService.registerRequestHandler(
        transportNodeAction, nodeRequest, nodeExecutor, new NodeTransportHandler());
}
项目:elasticsearch_my    文件:IcuTokenizerFactoryTests.java   
private static TestAnalysis createTestAnalysis() throws IOException {
    InputStream keywords = IcuTokenizerFactoryTests.class.getResourceAsStream("KeywordTokenizer.rbbi");
    InputStream latin = IcuTokenizerFactoryTests.class.getResourceAsStream("Latin-dont-break-on-hyphens.rbbi");

    Path home = createTempDir();
    Path config = home.resolve("config");
    Files.createDirectory(config);
    Files.copy(keywords, config.resolve("KeywordTokenizer.rbbi"));
    Files.copy(latin, config.resolve("Latin-dont-break-on-hyphens.rbbi"));

    String json = "/org/elasticsearch/index/analysis/icu_analysis.json";

    Settings settings = Settings.builder()
        .loadFromStream(json, IcuTokenizerFactoryTests.class.getResourceAsStream(json))
        .put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT)
        .build();
    Settings nodeSettings = Settings.builder().put(Environment.PATH_HOME_SETTING.getKey(), home).build();

    return createTestAnalysis(new Index("test", "_na_"), nodeSettings, settings, new AnalysisICUPlugin());
}
项目:Transwarp-Sample-Code    文件:SearchES.java   
/**
 * json查询
 */
public static void jsonquery() {
    try {
        Settings settings = Settings.settingsBuilder().put("cluster.name", "elasticsearch1").build();
        TransportClient transportClient = TransportClient.builder().
                settings(settings).build().addTransportAddress(
                new InetSocketTransportAddress(InetAddress.getByName("172.16.2.93"), 9300));
        SearchRequestBuilder searchRequestBuilder = transportClient.prepareSearch("service2");
        SearchResponse searchResponse = searchRequestBuilder.setSource("{\n" +
                "\"query\": {\n" +
                "\"bool\": {\n" +
                "\"must\": [\n" +
                "{\n" +
                "\"prefix\": {\n" +
                "\"content\": \"oracle\"\n" +
                "}\n" +
                "}\n" +
                "],\n" +
                "\"must_not\": [ ],\n" +
                "\"should\": [ ]\n" +
                "}\n" +
                "},\n" +
                "\"from\": 0,\n" +
                "\"size\": 10,\n" +
                "\"sort\": [ ],\n" +
                "\"aggs\": { }\n" +
                "}")
                .get();
        SearchHits searchHits = searchResponse.getHits();
        System.out.println();
        System.out.println("Total Hits is " + searchHits.totalHits());
        System.out.println();
        for (int i = 0; i < searchHits.getHits().length; ++i) {
            System.out.println("content is "
                    + searchHits.getHits()[i].getSource().get("content"));
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}
项目:elasticsearch_my    文件:RemoteClusterConnectionTests.java   
public void testDiscoverSingleNode() throws Exception {
    List<DiscoveryNode> knownNodes = new CopyOnWriteArrayList<>();
    try (MockTransportService seedTransport = startTransport("seed_node", knownNodes, Version.CURRENT);
         MockTransportService discoverableTransport = startTransport("discoverable_node", knownNodes, Version.CURRENT)) {
        DiscoveryNode seedNode = seedTransport.getLocalDiscoNode();
        DiscoveryNode discoverableNode = discoverableTransport.getLocalDiscoNode();
        knownNodes.add(seedTransport.getLocalDiscoNode());
        knownNodes.add(discoverableTransport.getLocalDiscoNode());
        Collections.shuffle(knownNodes, random());

        try (MockTransportService service = MockTransportService.createNewService(Settings.EMPTY, Version.CURRENT, threadPool, null)) {
            service.start();
            service.acceptIncomingRequests();
            try (RemoteClusterConnection connection = new RemoteClusterConnection(Settings.EMPTY, "test-cluster",
                Arrays.asList(seedNode), service, Integer.MAX_VALUE, n -> true)) {
                updateSeedNodes(connection, Arrays.asList(seedNode));
                assertTrue(service.nodeConnected(seedNode));
                assertTrue(service.nodeConnected(discoverableNode));
                assertTrue(connection.assertNoRunningConnections());
            }
        }
    }
}
项目:Elasticsearch    文件:PluginManagerCliParser.java   
public static void main(String[] args) {
    // initialize default for es.logger.level because we will not read the logging.yml
    String loggerLevel = System.getProperty("es.logger.level", "INFO");
    // Set the appender for all potential log files to terminal so that other components that use the logger print out the
    // same terminal.
    // The reason for this is that the plugin cli cannot be configured with a file appender because when the plugin command is
    // executed there is no way of knowing where the logfiles should be placed. For example, if elasticsearch
    // is run as service then the logs should be at /var/log/elasticsearch but when started from the tar they should be at es.home/logs.
    // Therefore we print to Terminal.
    Environment env = InternalSettingsPreparer.prepareEnvironment(Settings.builder()
            .put("appender.terminal.type", "terminal")
            .put("rootLogger", "${es.logger.level}, terminal")
            .put("es.logger.level", loggerLevel)
            .build(), Terminal.DEFAULT);
    // configure but do not read the logging conf file
    LogConfigurator.configure(env.settings(), false);
    int status = new PluginManagerCliParser().execute(args).status();
    exit(status);
}
项目:elasticsearch_my    文件:TransportTasksActionTests.java   
public void testTaskManagementOptOut() throws Exception {
    setupTestNodes(Settings.EMPTY);
    connectNodes(testNodes);
    CountDownLatch checkLatch = new CountDownLatch(1);
    // Starting actions that disable task manager
    ActionFuture<NodesResponse> future = startBlockingTestNodesAction(checkLatch, new NodesRequest("Test Request", false));

    TestNode testNode = testNodes[randomIntBetween(0, testNodes.length - 1)];

    // Get the parent task
    ListTasksRequest listTasksRequest = new ListTasksRequest();
    listTasksRequest.setActions("testAction*");
    ListTasksResponse response = testNode.transportListTasksAction.execute(listTasksRequest).get();
    assertEquals(0, response.getTasks().size());

    // Release all tasks and wait for response
    checkLatch.countDown();
    NodesResponse responses = future.get();
    assertEquals(0, responses.failureCount());
}
项目:elasticsearch_my    文件:ZenFaultDetectionTests.java   
protected MockTransportService build(Settings settings, Version version) {
    NamedWriteableRegistry namedWriteableRegistry = new NamedWriteableRegistry(Collections.emptyList());
    MockTransportService transportService =
        new MockTransportService(
            Settings.builder()
                .put(settings)
                // trace zenfd actions but keep the default otherwise
                .put(TransportService.TRACE_LOG_EXCLUDE_SETTING.getKey(), singleton(TransportLivenessAction.NAME))
                .build(),
            new MockTcpTransport(settings, threadPool, BigArrays.NON_RECYCLING_INSTANCE, circuitBreakerService,
                namedWriteableRegistry, new NetworkService(settings, Collections.emptyList()), version),
            threadPool,
            TransportService.NOOP_TRANSPORT_INTERCEPTOR,
            (boundAddress) ->
                new DiscoveryNode(Node.NODE_NAME_SETTING.get(settings), boundAddress.publishAddress(),
                    Node.NODE_ATTRIBUTES.get(settings).getAsMap(), DiscoveryNode.getRolesFromSettings(settings), version),
            null);
    transportService.start();
    transportService.acceptIncomingRequests();
    return transportService;
}
项目:elasticsearch_my    文件:PublishClusterStateActionTests.java   
public void testUnexpectedDiffPublishing() throws Exception {
    MockNode nodeA = createMockNode("nodeA", Settings.EMPTY, event -> {
        fail("Shouldn't send cluster state to myself");
    }).setAsMaster();

    MockNode nodeB = createMockNode("nodeB");

    // Initial cluster state with both states - the second node still shouldn't
    // get diff even though it's present in the previous cluster state
    DiscoveryNodes discoveryNodes = DiscoveryNodes.builder(nodeA.nodes()).add(nodeB.discoveryNode).build();
    ClusterState previousClusterState = ClusterState.builder(CLUSTER_NAME).nodes(discoveryNodes).build();
    ClusterState clusterState = ClusterState.builder(previousClusterState).incrementVersion().build();
    publishStateAndWait(nodeA.action, clusterState, previousClusterState);
    assertSameStateFromFull(nodeB.clusterState, clusterState);

    // cluster state update - add block
    previousClusterState = clusterState;
    clusterState = ClusterState.builder(clusterState).blocks(ClusterBlocks.builder()
        .addGlobalBlock(MetaData.CLUSTER_READ_ONLY_BLOCK)).incrementVersion().build();
    publishStateAndWait(nodeA.action, clusterState, previousClusterState);
    assertSameStateFromDiff(nodeB.clusterState, clusterState);
}
项目:elasticsearch_my    文件:Ec2DiscoveryTests.java   
public void testFilterByTags() throws InterruptedException {
    int nodes = randomIntBetween(5, 10);
    Settings nodeSettings = Settings.builder()
            .put(DISCOVERY_EC2.TAG_SETTING.getKey() + "stage", "prod")
            .build();

    int prodInstances = 0;
    List<List<Tag>> tagsList = new ArrayList<>();

    for (int node = 0; node < nodes; node++) {
        List<Tag> tags = new ArrayList<>();
        if (randomBoolean()) {
            tags.add(new Tag("stage", "prod"));
            prodInstances++;
        } else {
            tags.add(new Tag("stage", "dev"));
        }
        tagsList.add(tags);
    }

    logger.info("started [{}] instances with [{}] stage=prod tag", nodes, prodInstances);
    List<DiscoveryNode> discoveryNodes = buildDynamicNodes(nodeSettings, nodes, tagsList);
    assertThat(discoveryNodes, hasSize(prodInstances));
}
项目:elasticsearch_my    文件:ClusterSearchShardsIT.java   
public void testMultipleShardsSingleNodeAllocation() throws Exception {
    client().admin().indices().prepareCreate("test").setSettings(Settings.builder()
            .put("index.number_of_shards", "4").put("index.number_of_replicas", 0).put("index.routing.allocation.include.tag", "A")).execute().actionGet();
    ensureGreen();

    ClusterSearchShardsResponse response = client().admin().cluster().prepareSearchShards("test").execute().actionGet();
    assertThat(response.getGroups().length, equalTo(4));
    assertThat(response.getGroups()[0].getShardId().getIndexName(), equalTo("test"));
    assertThat(response.getNodes().length, equalTo(1));
    assertThat(response.getGroups()[0].getShards()[0].currentNodeId(), equalTo(response.getNodes()[0].getId()));

    response = client().admin().cluster().prepareSearchShards("test").setRouting("ABC").execute().actionGet();
    assertThat(response.getGroups().length, equalTo(1));

    response = client().admin().cluster().prepareSearchShards("test").setPreference("_shards:2").execute().actionGet();
    assertThat(response.getGroups().length, equalTo(1));
    assertThat(response.getGroups()[0].getShardId().getId(), equalTo(2));
}
项目:elasticsearch_my    文件:SettingsFilteringIT.java   
public void testSettingsFiltering() {
    assertAcked(client().admin().indices().prepareCreate("test-idx").setSettings(Settings.builder()
            .put("filter_test.foo", "test")
            .put("filter_test.bar1", "test")
            .put("filter_test.bar2", "test")
            .put("filter_test.notbar", "test")
            .put("filter_test.notfoo", "test")
            .build()).get());
    GetSettingsResponse response = client().admin().indices().prepareGetSettings("test-idx").get();
    Settings settings = response.getIndexToSettings().get("test-idx");

    assertThat(settings.get("index.filter_test.foo"), nullValue());
    assertThat(settings.get("index.filter_test.bar1"), nullValue());
    assertThat(settings.get("index.filter_test.bar2"), nullValue());
    assertThat(settings.get("index.filter_test.notbar"), equalTo("test"));
    assertThat(settings.get("index.filter_test.notfoo"), equalTo("test"));
}
项目:Elasticsearch    文件:AlterTableOperation.java   
private void addColumnToTable(AddColumnAnalyzedStatement analysis, final SettableFuture<Long> result) {
    boolean updateTemplate = analysis.table().isPartitioned();
    List<ListenableFuture<Long>> results = new ArrayList<>(2);
    final Map<String, Object> mapping = analysis.analyzedTableElements().toMapping();

    if (updateTemplate) {
        results.add(updateTemplate(mapping, Settings.EMPTY, analysis.table().ident(), analysis));
    }

    String[] indexNames = getIndexNames(analysis.table(), null);
    if (indexNames.length > 0) {
        results.add(updateMapping(mapping, indexNames));
    }

    applyMultiFutureCallback(result, results);
}
项目:elasticsearch_my    文件:DynamicMappingDisabledTests.java   
@Override
public void setUp() throws Exception {
    super.setUp();
    Settings settings = Settings.builder()
            .put(MapperService.INDEX_MAPPER_DYNAMIC_SETTING.getKey(), false)
            .build();
    clusterService = createClusterService(threadPool);
    Transport transport = new MockTcpTransport(settings, threadPool, BigArrays.NON_RECYCLING_INSTANCE,
            new NoneCircuitBreakerService(), new NamedWriteableRegistry(Collections.emptyList()),
            new NetworkService(settings, Collections.emptyList()));
    transportService = new TransportService(clusterService.getSettings(), transport, threadPool,
        TransportService.NOOP_TRANSPORT_INTERCEPTOR, x -> clusterService.localNode(), null);
    IndicesService indicesService = getInstanceFromNode(IndicesService.class);
    ShardStateAction shardStateAction = new ShardStateAction(settings, clusterService, transportService, null, null, threadPool);
    ActionFilters actionFilters = new ActionFilters(Collections.emptySet());
    IndexNameExpressionResolver indexNameExpressionResolver = new IndexNameExpressionResolver(settings);
    AutoCreateIndex autoCreateIndex = new AutoCreateIndex(settings, new ClusterSettings(settings,
            ClusterSettings.BUILT_IN_CLUSTER_SETTINGS), indexNameExpressionResolver);
    UpdateHelper updateHelper = new UpdateHelper(settings, null);
    TransportShardBulkAction shardBulkAction = new TransportShardBulkAction(settings, transportService, clusterService,
            indicesService, threadPool, shardStateAction, null, updateHelper, actionFilters, indexNameExpressionResolver);
    transportBulkAction = new TransportBulkAction(settings, threadPool, transportService, clusterService,
            null, shardBulkAction, null, actionFilters, indexNameExpressionResolver, autoCreateIndex, System::currentTimeMillis);
}
项目:es-sql    文件:Test.java   
public static String sqlToEsQuery(String sql) throws Exception {
        Map actions = new HashMap();
        Settings settings = Settings.builder().build();
//        Client client = new NodeClient(settings, null, null, actions);
//        Settings.builder()
//                .put(ThreadContext.PREFIX + ".key1", "val1")
//                .put(ThreadContext.PREFIX + ".key2", "val 2")
//                .build();

        ThreadPool threadPool = new ThreadPool(settings);
        Client client = new NodeClient(settings, threadPool);
        SearchDao searchDao = new org.nlpcn.es4sql.SearchDao(client);
        try {
            return searchDao.explain(sql).explain().explain();
        } catch (Exception e) {
            throw e;
        }
    }
项目:elasticsearch_my    文件:SimpleIcuCollationTokenFilterTests.java   
public void testCustomRules() throws Exception {
    RuleBasedCollator baseCollator = (RuleBasedCollator) Collator.getInstance(new ULocale("de_DE"));
    String DIN5007_2_tailorings =
            "& ae , a\u0308 & AE , A\u0308"+
                    "& oe , o\u0308 & OE , O\u0308"+
                    "& ue , u\u0308 & UE , u\u0308";

    RuleBasedCollator tailoredCollator = new RuleBasedCollator(baseCollator.getRules() + DIN5007_2_tailorings);
    String tailoredRules = tailoredCollator.getRules();

    Settings settings = Settings.builder()
            .put("index.analysis.filter.myCollator.type", "icu_collation")
            .put("index.analysis.filter.myCollator.rules", tailoredRules)
            .put("index.analysis.filter.myCollator.strength", "primary")
            .build();
    TestAnalysis analysis = createTestAnalysis(new Index("test", "_na_"), settings, new AnalysisICUPlugin());

    TokenFilterFactory filterFactory = analysis.tokenFilter.get("myCollator");
    assertCollatesToSame(filterFactory, "Töne", "Toene");
}
项目:elasticsearch_my    文件:DuelScrollIT.java   
private int createIndex(boolean singleShard) throws Exception {
    Settings.Builder settings = Settings.builder();
    if (singleShard) {
        settings.put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, 1);
    }
    // no replicas, as they might be ordered differently
    settings.put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 0);

    assertAcked(prepareCreate("test").setSettings(settings.build()).get());
    final int numDocs = randomIntBetween(10, 200);

    IndexRequestBuilder[] builders = new IndexRequestBuilder[numDocs];
    for (int i = 0; i < numDocs; ++i) {
        builders[i] = client().prepareIndex("test", "type", Integer.toString(i)).setSource("foo", random().nextBoolean());
    }
    indexRandom(true, builders);
    return numDocs;
}
项目:elasticsearch_my    文件:ScriptServiceTests.java   
public void testScriptCompiledOnceHiddenFileDetected() throws IOException {
    buildScriptService(Settings.EMPTY);

    Path testHiddenFile = scriptsFilePath.resolve(".hidden_file");
    Streams.copy("test_hidden_file".getBytes("UTF-8"), Files.newOutputStream(testHiddenFile));

    Path testFileScript = scriptsFilePath.resolve("file_script.test");
    Streams.copy("test_file_script".getBytes("UTF-8"), Files.newOutputStream(testFileScript));
    resourceWatcherService.notifyNow();

    CompiledScript compiledScript = scriptService.compile(new Script(ScriptType.FILE, "test", "file_script", Collections.emptyMap()),
            ScriptContext.Standard.SEARCH);
    assertThat(compiledScript.compiled(), equalTo((Object) "compiled_test_file_script"));

    Files.delete(testHiddenFile);
    Files.delete(testFileScript);
    resourceWatcherService.notifyNow();
}
项目:elasticsearch_my    文件:AwsS3ServiceImplTests.java   
public void testAWSCredentialsWithElasticsearchAwsAndS3AndRepositoriesSettingsAndRepositorySettingsBackcompat() {
    Settings repositorySettings = generateRepositorySettings("repository_key", "repository_secret", null, null);
    Settings settings = Settings.builder()
        .put(AwsS3Service.KEY_SETTING.getKey(), "aws_key")
        .put(AwsS3Service.SECRET_SETTING.getKey(), "aws_secret")
        .put(AwsS3Service.CLOUD_S3.KEY_SETTING.getKey(), "s3_key")
        .put(AwsS3Service.CLOUD_S3.SECRET_SETTING.getKey(), "s3_secret")
        .put(S3Repository.Repositories.KEY_SETTING.getKey(), "repositories_key")
        .put(S3Repository.Repositories.SECRET_SETTING.getKey(), "repositories_secret")
        .build();
    launchAWSCredentialsWithElasticsearchSettingsTest(repositorySettings, settings, "repository_key", "repository_secret");
     assertSettingDeprecationsAndWarnings(
             new Setting<?>[]{S3Repository.Repository.KEY_SETTING, S3Repository.Repository.SECRET_SETTING});
}
项目:Elasticsearch    文件:TransportShardRefreshAction.java   
@Inject
public TransportShardRefreshAction(Settings settings, TransportService transportService, ClusterService clusterService,
                                   IndicesService indicesService, ThreadPool threadPool, ShardStateAction shardStateAction,
                                   MappingUpdatedAction mappingUpdatedAction, ActionFilters actionFilters,
                                   IndexNameExpressionResolver indexNameExpressionResolver) {
    super(settings, NAME, transportService, clusterService, indicesService, threadPool, shardStateAction, mappingUpdatedAction,
            actionFilters, indexNameExpressionResolver, ReplicationRequest.class, ReplicationRequest.class, ThreadPool.Names.REFRESH);
}
项目:elasticsearch_my    文件:FsService.java   
public FsService(final Settings settings, final NodeEnvironment nodeEnvironment, ClusterInfoService clusterInfoService) {
    super(settings);
    this.probe = new FsProbe(settings, nodeEnvironment);
    this.clusterInfoService = clusterInfoService;
    refreshInterval = REFRESH_INTERVAL_SETTING.get(settings);
    logger.debug("using refresh_interval [{}]", refreshInterval);
    cache = new FsInfoCache(refreshInterval, stats(probe, null, logger, null));
}
项目:Elasticsearch    文件:RestNodesInfoAction.java   
@Inject
public RestNodesInfoAction(Settings settings, RestController controller, Client client, SettingsFilter settingsFilter) {
    super(settings, controller, client);
    controller.registerHandler(GET, "/_nodes", this);
    // this endpoint is used for metrics, not for nodeIds, like /_nodes/fs
    controller.registerHandler(GET, "/_nodes/{nodeId}", this);
    controller.registerHandler(GET, "/_nodes/{nodeId}/{metrics}", this);
    // added this endpoint to be aligned with stats
    controller.registerHandler(GET, "/_nodes/{nodeId}/info/{metrics}", this);

    this.settingsFilter = settingsFilter;
}
项目:elasticsearch_my    文件:TransportShardRefreshAction.java   
@Inject
public TransportShardRefreshAction(Settings settings, TransportService transportService, ClusterService clusterService,
                                   IndicesService indicesService, ThreadPool threadPool, ShardStateAction shardStateAction,
                                   ActionFilters actionFilters, IndexNameExpressionResolver indexNameExpressionResolver) {
    super(settings, NAME, transportService, clusterService, indicesService, threadPool, shardStateAction, actionFilters,
            indexNameExpressionResolver, BasicReplicationRequest::new, BasicReplicationRequest::new, ThreadPool.Names.REFRESH);
}
项目:elasticsearch_my    文件:StandardHtmlStripAnalyzerProvider.java   
public StandardHtmlStripAnalyzerProvider(IndexSettings indexSettings, Environment env,  String name, Settings settings) {
    super(indexSettings, name, settings);
    final CharArraySet defaultStopwords = CharArraySet.EMPTY_SET;
    CharArraySet stopWords = Analysis.parseStopWords(env, indexSettings.getIndexVersionCreated(), settings, defaultStopwords);
    analyzer = new StandardHtmlStripAnalyzer(stopWords);
    analyzer.setVersion(version);
}
项目:elasticsearch_my    文件:AzureMinimumMasterNodesTests.java   
@Override
protected Settings nodeSettings(int nodeOrdinal) {
    Settings.Builder builder = Settings.builder()
            .put(super.nodeSettings(nodeOrdinal))
            .put("discovery.zen.minimum_master_nodes", 2)
            // Make the test run faster
            .put(ZenDiscovery.JOIN_TIMEOUT_SETTING.getKey(), "50ms")
            .put(ZenDiscovery.PING_TIMEOUT_SETTING.getKey(), "10ms")
            .put("discovery.initial_state_timeout", "100ms");
    return builder.build();
}
项目:elasticsearch_my    文件:RestCountAction.java   
public RestCountAction(Settings settings, RestController controller) {
    super(settings);
    controller.registerHandler(POST, "/_count", this);
    controller.registerHandler(GET, "/_count", this);
    controller.registerHandler(POST, "/{index}/_count", this);
    controller.registerHandler(GET, "/{index}/_count", this);
    controller.registerHandler(POST, "/{index}/{type}/_count", this);
    controller.registerHandler(GET, "/{index}/{type}/_count", this);
}
项目:elasticsearch_my    文件:DFRSimilarityProvider.java   
/**
 * Parses the given Settings and creates the appropriate {@link BasicModel}
 *
 * @param settings Settings to parse
 * @return {@link BasicModel} referred to in the Settings
 */
protected BasicModel parseBasicModel(Settings settings) {
    String basicModel = settings.get("basic_model");
    BasicModel model = BASIC_MODELS.get(basicModel);
    if (model == null) {
        throw new IllegalArgumentException("Unsupported BasicModel [" + basicModel + "]");
    }
    return model;
}
项目:elasticsearch_my    文件:SumIT.java   
/**
 * Make sure that a request using a script does not get cached and a request
 * not using a script does get cached.
 */
public void testDontCacheScripts() throws Exception {
    assertAcked(prepareCreate("cache_test_idx").addMapping("type", "d", "type=long")
            .setSettings(Settings.builder().put("requests.cache.enable", true).put("number_of_shards", 1).put("number_of_replicas", 1))
            .get());
    indexRandom(true, client().prepareIndex("cache_test_idx", "type", "1").setSource("s", 1),
            client().prepareIndex("cache_test_idx", "type", "2").setSource("s", 2));

    // Make sure we are starting with a clear cache
    assertThat(client().admin().indices().prepareStats("cache_test_idx").setRequestCache(true).get().getTotal().getRequestCache()
            .getHitCount(), equalTo(0L));
    assertThat(client().admin().indices().prepareStats("cache_test_idx").setRequestCache(true).get().getTotal().getRequestCache()
            .getMissCount(), equalTo(0L));

    // Test that a request using a script does not get cached
    SearchResponse r = client().prepareSearch("cache_test_idx").setSize(0)
            .addAggregation(sum("foo").field("d").script(
                new Script(ScriptType.INLINE, FieldValueScriptEngine.NAME, "", Collections.emptyMap()))).get();
    assertSearchResponse(r);

    assertThat(client().admin().indices().prepareStats("cache_test_idx").setRequestCache(true).get().getTotal().getRequestCache()
            .getHitCount(), equalTo(0L));
    assertThat(client().admin().indices().prepareStats("cache_test_idx").setRequestCache(true).get().getTotal().getRequestCache()
            .getMissCount(), equalTo(0L));

    // To make sure that the cache is working test that a request not using
    // a script is cached
    r = client().prepareSearch("cache_test_idx").setSize(0).addAggregation(sum("foo").field("d")).get();
    assertSearchResponse(r);

    assertThat(client().admin().indices().prepareStats("cache_test_idx").setRequestCache(true).get().getTotal().getRequestCache()
            .getHitCount(), equalTo(0L));
    assertThat(client().admin().indices().prepareStats("cache_test_idx").setRequestCache(true).get().getTotal().getRequestCache()
            .getMissCount(), equalTo(1L));
}
项目:elasticsearch-analysis-voikko    文件:VoikkoTokenFilterTests.java   
private TestAnalysis getAnalysisService() {
    try {
        Settings indexSettings = Settings.builder()
                .put(settings.build())
                .put("index.analysis.analyzer.test.type", "custom")
                .put("index.analysis.analyzer.test.tokenizer", "finnish")
                .putArray("index.analysis.analyzer.test.filter", "lowercase", "myFilter")
                .build();

        return createTestAnalysis(new Index("test", "_na_"), indexSettings, new AnalysisVoikkoPlugin());
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}
项目:Elasticsearch    文件:SnowballAnalyzerProvider.java   
@Inject
public SnowballAnalyzerProvider(Index index, IndexSettingsService indexSettingsService, Environment env, @Assisted String name, @Assisted Settings settings) {
    super(index, indexSettingsService.getSettings(), name, settings);

    String language = settings.get("language", settings.get("name", "English"));
    CharArraySet defaultStopwords = defaultLanguageStopwords.containsKey(language) ? defaultLanguageStopwords.get(language) : CharArraySet.EMPTY_SET;
    CharArraySet stopWords = Analysis.parseStopWords(env, settings, defaultStopwords);

    analyzer = new SnowballAnalyzer(language, stopWords);
    analyzer.setVersion(version);
}
项目:elasticsearch_my    文件:ScriptModesTests.java   
public void testConflictingScriptTypeAndOpGenericSettings() {
    ScriptContext scriptContext = randomFrom(scriptContexts);
    Settings.Builder builder = Settings.builder()
            .put("script." + scriptContext.getKey(), "false")
            .put("script.stored", "true")
            .put("script.inline", "true");
    //operations generic settings have precedence over script type generic settings
    this.scriptModes = new ScriptModes(scriptSettings, builder.build());
    assertScriptModesAllTypes(false, scriptContext);
    ScriptContext[] complementOf = complementOf(scriptContext);
    assertScriptModes(true, new ScriptType[]{ScriptType.FILE, ScriptType.STORED}, complementOf);
    assertScriptModes(true, new ScriptType[]{ScriptType.INLINE}, complementOf);
}
项目:elasticsearch_my    文件:IndexShardTests.java   
public void testShardStats() throws IOException {

        IndexShard shard = newStartedShard();
        ShardStats stats = new ShardStats(shard.routingEntry(), shard.shardPath(),
            new CommonStats(new IndicesQueryCache(Settings.EMPTY), shard, new CommonStatsFlags()), shard.commitStats(), shard.seqNoStats());
        assertEquals(shard.shardPath().getRootDataPath().toString(), stats.getDataPath());
        assertEquals(shard.shardPath().getRootStatePath().toString(), stats.getStatePath());
        assertEquals(shard.shardPath().isCustomDataPath(), stats.isCustomDataPath());

        if (randomBoolean() || true) { // try to serialize it to ensure values survive the serialization
            BytesStreamOutput out = new BytesStreamOutput();
            stats.writeTo(out);
            StreamInput in = out.bytes().streamInput();
            stats = ShardStats.readShardStats(in);
        }
        XContentBuilder builder = jsonBuilder();
        builder.startObject();
        stats.toXContent(builder, EMPTY_PARAMS);
        builder.endObject();
        String xContent = builder.string();
        StringBuilder expectedSubSequence = new StringBuilder("\"shard_path\":{\"state_path\":\"");
        expectedSubSequence.append(shard.shardPath().getRootStatePath().toString());
        expectedSubSequence.append("\",\"data_path\":\"");
        expectedSubSequence.append(shard.shardPath().getRootDataPath().toString());
        expectedSubSequence.append("\",\"is_custom_data_path\":").append(shard.shardPath().isCustomDataPath()).append("}");
        if (Constants.WINDOWS) {
            // Some path weirdness on windows
        } else {
            assertTrue(xContent.contains(expectedSubSequence));
        }
        closeShards(shard);
    }
项目:Elasticsearch    文件:PatternReplaceTokenFilterFactory.java   
@Inject
public PatternReplaceTokenFilterFactory(Index index, IndexSettingsService indexSettingsService, @Assisted String name, @Assisted Settings settings) {
    super(index, indexSettingsService.getSettings(), name, settings);

    String sPattern = settings.get("pattern", null);
    if (sPattern == null) {
        throw new IllegalArgumentException("pattern is missing for [" + name + "] token filter of type 'pattern_replace'");
    }
    this.pattern = Regex.compile(sPattern, settings.get("flags"));
    this.replacement = settings.get("replacement", "");
    this.all = settings.getAsBoolean("all", true);
}
项目:elasticsearch_my    文件:IndexModuleTests.java   
public void testSetupUnknownSimilarity() throws IOException {
    Settings indexSettings = Settings.builder()
            .put("index.similarity.my_similarity.type", "test_similarity")
            .put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT)
            .put(Environment.PATH_HOME_SETTING.getKey(), createTempDir().toString())
            .build();
    IndexModule module = new IndexModule(IndexSettingsModule.newIndexSettings("foo", indexSettings),
            new AnalysisRegistry(environment, emptyMap(), emptyMap(), emptyMap(), emptyMap(), emptyMap()));
    Exception ex = expectThrows(IllegalArgumentException.class, () -> newIndexService(module));
    assertEquals("Unknown Similarity type [test_similarity] for [my_similarity]", ex.getMessage());
}
项目:elasticsearch_my    文件:RestNoopBulkAction.java   
public RestNoopBulkAction(Settings settings, RestController controller) {
    super(settings);

    controller.registerHandler(POST, "/_noop_bulk", this);
    controller.registerHandler(PUT, "/_noop_bulk", this);
    controller.registerHandler(POST, "/{index}/_noop_bulk", this);
    controller.registerHandler(PUT, "/{index}/_noop_bulk", this);
    controller.registerHandler(POST, "/{index}/{type}/_noop_bulk", this);
    controller.registerHandler(PUT, "/{index}/{type}/_noop_bulk", this);
}
项目:elasticsearch_my    文件:IndexRecoveryIT.java   
private void slowDownRecovery(ByteSizeValue shardSize) {
    long chunkSize = Math.max(1, shardSize.getBytes() / 10);
    assertTrue(client().admin().cluster().prepareUpdateSettings()
            .setTransientSettings(Settings.builder()
                            // one chunk per sec..
                            .put(RecoverySettings.INDICES_RECOVERY_MAX_BYTES_PER_SEC_SETTING.getKey(), chunkSize, ByteSizeUnit.BYTES)
                            // small chunks
                            .put(CHUNK_SIZE_SETTING.getKey(), new ByteSizeValue(chunkSize, ByteSizeUnit.BYTES))
            ).get().isAcknowledged());
}
项目:elasticsearch_my    文件:AbstractSuggestionBuilderTestCase.java   
/**
 * setup for the whole base test class
 */
@BeforeClass
public static void init() throws IOException {
    SearchModule searchModule = new SearchModule(Settings.EMPTY, false, emptyList());
    namedWriteableRegistry = new NamedWriteableRegistry(searchModule.getNamedWriteables());
    xContentRegistry = new NamedXContentRegistry(searchModule.getNamedXContents());
}
项目:Elasticsearch    文件:TransportClusterStatsAction.java   
@Inject
public TransportClusterStatsAction(Settings settings, ClusterName clusterName, ThreadPool threadPool,
                                   ClusterService clusterService, TransportService transportService,
                                   NodeService nodeService, IndicesService indicesService,
                                   ActionFilters actionFilters, IndexNameExpressionResolver indexNameExpressionResolver) {
    super(settings, ClusterStatsAction.NAME, clusterName, threadPool, clusterService, transportService, actionFilters,
            indexNameExpressionResolver, ClusterStatsRequest.class, ClusterStatsNodeRequest.class, ThreadPool.Names.MANAGEMENT);
    this.nodeService = nodeService;
    this.indicesService = indicesService;
}
项目:elasticsearch_my    文件:EnableAllocationDecider.java   
public EnableAllocationDecider(Settings settings, ClusterSettings clusterSettings) {
    super(settings);
    this.enableAllocation = CLUSTER_ROUTING_ALLOCATION_ENABLE_SETTING.get(settings);
    this.enableRebalance = CLUSTER_ROUTING_REBALANCE_ENABLE_SETTING.get(settings);
    clusterSettings.addSettingsUpdateConsumer(CLUSTER_ROUTING_ALLOCATION_ENABLE_SETTING, this::setEnableAllocation);
    clusterSettings.addSettingsUpdateConsumer(CLUSTER_ROUTING_REBALANCE_ENABLE_SETTING, this::setEnableRebalance);
}
项目:Elasticsearch    文件:DiscoveryService.java   
public static String generateNodeId(Settings settings) {
    String seed = settings.get(DiscoveryService.SETTING_DISCOVERY_SEED);
    if (seed != null) {
        return Strings.randomBase64UUID(new Random(Long.parseLong(seed)));
    }
    return Strings.randomBase64UUID();
}
项目:elasticsearch_my    文件:Netty4PipeliningDisabledIT.java   
@Override
protected Settings nodeSettings(int nodeOrdinal) {
    return Settings.builder()
        .put(super.nodeSettings(nodeOrdinal))
        .put(NetworkModule.HTTP_ENABLED.getKey(), true)
        .put("http.pipelining", false)
        .build();
}