use of org.elasticsearch.cluster.ClusterState in project crate by crate.
the class CreateAlterPartitionedTableAnalyzerTest method init.
@Before
public void init() throws Exception {
String analyzerSettings = FulltextAnalyzerResolver.encodeSettings(Settings.builder().put("search", "foobar").build()).toUtf8();
MetaData metaData = MetaData.builder().persistentSettings(Settings.builder().put("crate.analysis.custom.analyzer.ft_search", analyzerSettings).build()).build();
ClusterState state = ClusterState.builder(ClusterName.DEFAULT).metaData(metaData).build();
e = SQLExecutor.builder(new NoopClusterService(state)).enableDefaultTables().build();
}
use of org.elasticsearch.cluster.ClusterState in project rssriver by dadoonet.
the class RssRiver method isMappingExist.
/**
* Check if a mapping already exists in an index
* @param index Index name
* @param type Mapping name
* @return true if mapping exists
*/
private boolean isMappingExist(String index, String type) {
ClusterState cs = client.admin().cluster().prepareState().setIndices(index).execute().actionGet().getState();
IndexMetaData imd = cs.getMetaData().index(index);
if (imd == null)
return false;
MappingMetaData mdd = imd.mapping(type);
if (mdd != null)
return true;
return false;
}
use of org.elasticsearch.cluster.ClusterState in project elasticsearch by elastic.
the class ScriptContextTests method makeScriptService.
ScriptService makeScriptService() throws Exception {
Settings settings = Settings.builder().put(Environment.PATH_HOME_SETTING.getKey(), createTempDir()).put(ScriptService.SCRIPT_AUTO_RELOAD_ENABLED_SETTING.getKey(), "false").put("script." + PLUGIN_NAME + "_custom_globally_disabled_op", "false").put("script.engine." + MockScriptEngine.NAME + ".inline." + PLUGIN_NAME + "_custom_exp_disabled_op", "false").build();
MockScriptEngine scriptEngine = new MockScriptEngine(MockScriptEngine.NAME, Collections.singletonMap("1", script -> "1"));
ScriptEngineRegistry scriptEngineRegistry = new ScriptEngineRegistry(Collections.singletonList(scriptEngine));
List<ScriptContext.Plugin> customContexts = Arrays.asList(new ScriptContext.Plugin(PLUGIN_NAME, "custom_op"), new ScriptContext.Plugin(PLUGIN_NAME, "custom_exp_disabled_op"), new ScriptContext.Plugin(PLUGIN_NAME, "custom_globally_disabled_op"));
ScriptContextRegistry scriptContextRegistry = new ScriptContextRegistry(customContexts);
ScriptSettings scriptSettings = new ScriptSettings(scriptEngineRegistry, scriptContextRegistry);
ScriptService scriptService = new ScriptService(settings, new Environment(settings), null, scriptEngineRegistry, scriptContextRegistry, scriptSettings);
ClusterState empty = ClusterState.builder(new ClusterName("_name")).build();
ScriptMetaData smd = empty.metaData().custom(ScriptMetaData.TYPE);
smd = ScriptMetaData.putStoredScript(smd, "1", new StoredScriptSource(MockScriptEngine.NAME, "1", Collections.emptyMap()));
MetaData.Builder mdb = MetaData.builder(empty.getMetaData()).putCustom(ScriptMetaData.TYPE, smd);
ClusterState stored = ClusterState.builder(empty).metaData(mdb).build();
scriptService.clusterChanged(new ClusterChangedEvent("test", stored, empty));
return scriptService;
}
use of org.elasticsearch.cluster.ClusterState in project elasticsearch by elastic.
the class AliasResolveRoutingIT method testResolveSearchRouting.
public void testResolveSearchRouting() throws Exception {
createIndex("test1");
createIndex("test2");
client().admin().cluster().prepareHealth().setWaitForEvents(Priority.LANGUID).setWaitForGreenStatus().execute().actionGet();
client().admin().indices().prepareAliases().addAliasAction(AliasActions.add().index("test1").alias("alias")).addAliasAction(AliasActions.add().index("test1").alias("alias10").routing("0")).addAliasAction(AliasActions.add().index("test2").alias("alias20").routing("0")).addAliasAction(AliasActions.add().index("test2").alias("alias21").routing("1")).addAliasAction(AliasActions.add().index("test1").alias("alias0").routing("0")).addAliasAction(AliasActions.add().index("test2").alias("alias0").routing("0")).get();
ClusterState state = clusterService().state();
IndexNameExpressionResolver indexNameExpressionResolver = internalCluster().getInstance(IndexNameExpressionResolver.class);
assertThat(indexNameExpressionResolver.resolveSearchRouting(state, null, "alias"), nullValue());
assertThat(indexNameExpressionResolver.resolveSearchRouting(state, "0,1", "alias"), equalTo(newMap("test1", newSet("0", "1"))));
assertThat(indexNameExpressionResolver.resolveSearchRouting(state, null, "alias10"), equalTo(newMap("test1", newSet("0"))));
assertThat(indexNameExpressionResolver.resolveSearchRouting(state, null, "alias10"), equalTo(newMap("test1", newSet("0"))));
assertThat(indexNameExpressionResolver.resolveSearchRouting(state, "0", "alias10"), equalTo(newMap("test1", newSet("0"))));
assertThat(indexNameExpressionResolver.resolveSearchRouting(state, "1", "alias10"), nullValue());
assertThat(indexNameExpressionResolver.resolveSearchRouting(state, null, "alias0"), equalTo(newMap("test1", newSet("0"), "test2", newSet("0"))));
assertThat(indexNameExpressionResolver.resolveSearchRouting(state, null, new String[] { "alias10", "alias20" }), equalTo(newMap("test1", newSet("0"), "test2", newSet("0"))));
assertThat(indexNameExpressionResolver.resolveSearchRouting(state, null, new String[] { "alias10", "alias21" }), equalTo(newMap("test1", newSet("0"), "test2", newSet("1"))));
assertThat(indexNameExpressionResolver.resolveSearchRouting(state, null, new String[] { "alias20", "alias21" }), equalTo(newMap("test2", newSet("0", "1"))));
assertThat(indexNameExpressionResolver.resolveSearchRouting(state, null, new String[] { "test1", "alias10" }), nullValue());
assertThat(indexNameExpressionResolver.resolveSearchRouting(state, null, new String[] { "alias10", "test1" }), nullValue());
assertThat(indexNameExpressionResolver.resolveSearchRouting(state, "0", new String[] { "alias10", "alias20" }), equalTo(newMap("test1", newSet("0"), "test2", newSet("0"))));
assertThat(indexNameExpressionResolver.resolveSearchRouting(state, "0,1", new String[] { "alias10", "alias20" }), equalTo(newMap("test1", newSet("0"), "test2", newSet("0"))));
assertThat(indexNameExpressionResolver.resolveSearchRouting(state, "1", new String[] { "alias10", "alias20" }), nullValue());
assertThat(indexNameExpressionResolver.resolveSearchRouting(state, "0", new String[] { "alias10", "alias21" }), equalTo(newMap("test1", newSet("0"))));
assertThat(indexNameExpressionResolver.resolveSearchRouting(state, "1", new String[] { "alias10", "alias21" }), equalTo(newMap("test2", newSet("1"))));
assertThat(indexNameExpressionResolver.resolveSearchRouting(state, "0,1,2", new String[] { "alias10", "alias21" }), equalTo(newMap("test1", newSet("0"), "test2", newSet("1"))));
assertThat(indexNameExpressionResolver.resolveSearchRouting(state, "0,1,2", new String[] { "test1", "alias10", "alias21" }), equalTo(newMap("test1", newSet("0", "1", "2"), "test2", newSet("1"))));
}
use of org.elasticsearch.cluster.ClusterState in project elasticsearch by elastic.
the class ParentFieldLoadingIT method testChangingEagerParentFieldLoadingAtRuntime.
public void testChangingEagerParentFieldLoadingAtRuntime() throws Exception {
assertAcked(prepareCreate("test").setSettings(indexSettings).addMapping("parent").addMapping("child", "_parent", "type=parent"));
ensureGreen();
client().prepareIndex("test", "parent", "1").setSource("{}", XContentType.JSON).get();
client().prepareIndex("test", "child", "1").setParent("1").setSource("{}", XContentType.JSON).get();
refresh();
ClusterStatsResponse response = client().admin().cluster().prepareClusterStats().get();
assertThat(response.getIndicesStats().getFieldData().getMemorySizeInBytes(), equalTo(0L));
PutMappingResponse putMappingResponse = client().admin().indices().preparePutMapping("test").setType("child").setSource(childMapping(true)).setUpdateAllTypes(true).get();
assertAcked(putMappingResponse);
Index test = resolveIndex("test");
assertBusy(new Runnable() {
@Override
public void run() {
ClusterState clusterState = internalCluster().clusterService().state();
ShardRouting shardRouting = clusterState.routingTable().index("test").shard(0).getShards().get(0);
String nodeName = clusterState.getNodes().get(shardRouting.currentNodeId()).getName();
boolean verified = false;
IndicesService indicesService = internalCluster().getInstance(IndicesService.class, nodeName);
IndexService indexService = indicesService.indexService(test);
if (indexService != null) {
MapperService mapperService = indexService.mapperService();
DocumentMapper documentMapper = mapperService.documentMapper("child");
if (documentMapper != null) {
verified = documentMapper.parentFieldMapper().fieldType().eagerGlobalOrdinals();
}
}
assertTrue(verified);
}
});
// Need to add a new doc otherwise the refresh doesn't trigger a new searcher
// Because it ends up in its own segment, but isn't of type parent or child, this doc doesn't contribute to the size of the fielddata cache
client().prepareIndex("test", "dummy", "dummy").setSource("{}", XContentType.JSON).get();
refresh();
response = client().admin().cluster().prepareClusterStats().get();
assertThat(response.getIndicesStats().getFieldData().getMemorySizeInBytes(), greaterThan(0L));
}
Aggregations