本文整理匯總了Java中org.elasticsearch.common.settings.Settings類的典型用法代碼示例。如果您正苦於以下問題:Java Settings類的具體用法?Java Settings怎麽用?Java Settings使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
Settings類屬於org.elasticsearch.common.settings包,在下文中一共展示了Settings類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: jsonquery
import org.elasticsearch.common.settings.Settings; //導入依賴的package包/類
/**
* 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();
}
}
示例2: testSettingsFiltering
import org.elasticsearch.common.settings.Settings; //導入依賴的package包/類
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"));
}
示例3: sqlToEsQuery
import org.elasticsearch.common.settings.Settings; //導入依賴的package包/類
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;
}
}
示例4: testCustomRules
import org.elasticsearch.common.settings.Settings; //導入依賴的package包/類
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");
}
示例5: TransportNodesAction
import org.elasticsearch.common.settings.Settings; //導入依賴的package包/類
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());
}
示例6: createTestAnalysis
import org.elasticsearch.common.settings.Settings; //導入依賴的package包/類
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());
}
示例7: testDiscoverSingleNode
import org.elasticsearch.common.settings.Settings; //導入依賴的package包/類
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());
}
}
}
}
示例8: main
import org.elasticsearch.common.settings.Settings; //導入依賴的package包/類
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);
}
示例9: testTaskManagementOptOut
import org.elasticsearch.common.settings.Settings; //導入依賴的package包/類
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());
}
示例10: build
import org.elasticsearch.common.settings.Settings; //導入依賴的package包/類
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;
}
示例11: testUnexpectedDiffPublishing
import org.elasticsearch.common.settings.Settings; //導入依賴的package包/類
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);
}
示例12: testMultipleShardsSingleNodeAllocation
import org.elasticsearch.common.settings.Settings; //導入依賴的package包/類
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));
}
示例13: addColumnToTable
import org.elasticsearch.common.settings.Settings; //導入依賴的package包/類
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);
}
示例14: setUp
import org.elasticsearch.common.settings.Settings; //導入依賴的package包/類
@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);
}
示例15: createIndex
import org.elasticsearch.common.settings.Settings; //導入依賴的package包/類
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;
}