Java Code Examples for org.elasticsearch.common.Strings#EMPTY_ARRAY

The following examples show how to use org.elasticsearch.common.Strings#EMPTY_ARRAY . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Test.java    From dht-spider with MIT License 6 votes vote down vote up
public static void get(Map<String, Object> m) throws Exception{
    GetRequest getRequest = new GetRequest(
            "haha",
            "doc",
            "2");
    String[] includes = new String[]{"message","user","*Date"};
    String[] excludes = Strings.EMPTY_ARRAY;
    FetchSourceContext fetchSourceContext =
            new FetchSourceContext(true, includes, excludes);
    getRequest.fetchSourceContext(fetchSourceContext);

    GetResponse getResponse = client.get(getRequest, RequestOptions.DEFAULT);
    String index = getResponse.getIndex();
    String type = getResponse.getType();
    String id = getResponse.getId();
    if (getResponse.isExists()) {
        long version = getResponse.getVersion();
        String sourceAsString = getResponse.getSourceAsString();
        Map<String, Object> sourceAsMap = getResponse.getSourceAsMap();
        System.out.println(sourceAsMap);
    } else {

    }
}
 
Example 2
Source File: ClusterHealthRequest.java    From crate with Apache License 2.0 6 votes vote down vote up
public ClusterHealthRequest(StreamInput in) throws IOException {
    super(in);
    int size = in.readVInt();
    if (size == 0) {
        indices = Strings.EMPTY_ARRAY;
    } else {
        indices = new String[size];
        for (int i = 0; i < indices.length; i++) {
            indices[i] = in.readString();
        }
    }
    timeout = in.readTimeValue();
    if (in.readBoolean()) {
        waitForStatus = ClusterHealthStatus.fromValue(in.readByte());
    }
    waitForNoRelocatingShards = in.readBoolean();
    waitForActiveShards = ActiveShardCount.readFrom(in);
    waitForNodes = in.readString();
    if (in.readBoolean()) {
        waitForEvents = Priority.readFrom(in);
    }
    waitForNoInitializingShards = in.readBoolean();
}
 
Example 3
Source File: Search.java    From elasticsearch-rest-command with The Unlicense 6 votes vote down vote up
public static String[] parseIndices(AST_Search searchTree, Client client) throws CommandException {
	String[] indices = Strings.EMPTY_ARRAY;

	// 过滤不存在的index,不然查询会失败
	// 如果所有指定的index都不存在,那么将在所有的index查询该条件
	String[] originIndices = ((String) searchTree.getOption(Option.INDEX))
			.split(",");
	ArrayList<String> listIndices = new ArrayList<String>();

	for (String index : originIndices) {
		if (client.admin().indices()
				.exists(new IndicesExistsRequest(index)).actionGet()
				.isExists()) {
			listIndices.add(index);
		}
	}

	if (listIndices.size() > 0)
		indices = listIndices.toArray(new String[listIndices.size()]);
	else
		throw new CommandException(String.format("%s index not exsit", searchTree.getOption(Option.INDEX)));
	
	return indices;

}
 
Example 4
Source File: TransportClusterHealthAction.java    From crate with Apache License 2.0 6 votes vote down vote up
private ClusterHealthResponse clusterHealth(ClusterHealthRequest request, ClusterState clusterState, int numberOfPendingTasks, int numberOfInFlightFetch,
                                            TimeValue pendingTaskTimeInQueue) {
    if (logger.isTraceEnabled()) {
        logger.trace("Calculating health based on state version [{}]", clusterState.version());
    }

    String[] concreteIndices;
    try {
        concreteIndices = indexNameExpressionResolver.concreteIndexNames(clusterState, request);
    } catch (IndexNotFoundException e) {
        // one of the specified indices is not there - treat it as RED.
        ClusterHealthResponse response = new ClusterHealthResponse(clusterState.getClusterName().value(), Strings.EMPTY_ARRAY, clusterState,
                numberOfPendingTasks, numberOfInFlightFetch, UnassignedInfo.getNumberOfDelayedUnassigned(clusterState),
                pendingTaskTimeInQueue);
        response.setStatus(ClusterHealthStatus.RED);
        return response;
    }

    return new ClusterHealthResponse(clusterState.getClusterName().value(), concreteIndices, clusterState, numberOfPendingTasks,
            numberOfInFlightFetch, UnassignedInfo.getNumberOfDelayedUnassigned(clusterState), pendingTaskTimeInQueue);
}
 
Example 5
Source File: MappingMetaData.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
public ParsedVersion(String path, VersionType versionType) {
    this.path = path;
    if (path == null) {
        this.pathElements = Strings.EMPTY_ARRAY;
        this.versionType = VersionType.INTERNAL;
    } else {
        this.versionType = versionType;
        this.pathElements = Strings.delimitedListToStringArray(path, ".");
    }
}
 
Example 6
Source File: MappingMetaData.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
public Id(String path) {
    this.path = path;
    if (path == null) {
        pathElements = Strings.EMPTY_ARRAY;
    } else {
        pathElements = Strings.delimitedListToStringArray(path, ".");
    }
}
 
Example 7
Source File: TribeService.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
@Inject
public TribeService(Settings settings, ClusterService clusterService, DiscoveryService discoveryService) {
    super(settings);
    this.clusterService = clusterService;
    Map<String, Settings> nodesSettings = Maps.newHashMap(settings.getGroups("tribe", true));
    nodesSettings.remove("blocks"); // remove prefix settings that don't indicate a client
    nodesSettings.remove("on_conflict"); // remove prefix settings that don't indicate a client
    for (Map.Entry<String, Settings> entry : nodesSettings.entrySet()) {
        Settings clientSettings = buildClientSettings(entry.getKey(), settings, entry.getValue());
        nodes.add(new TribeClientNode(clientSettings));
    }

    String[] blockIndicesWrite = Strings.EMPTY_ARRAY;
    String[] blockIndicesRead = Strings.EMPTY_ARRAY;
    String[] blockIndicesMetadata = Strings.EMPTY_ARRAY;
    if (!nodes.isEmpty()) {
        // remove the initial election / recovery blocks since we are not going to have a
        // master elected in this single tribe  node local "cluster"
        clusterService.removeInitialStateBlock(discoveryService.getNoMasterBlock());
        clusterService.removeInitialStateBlock(GatewayService.STATE_NOT_RECOVERED_BLOCK);
        if (settings.getAsBoolean("tribe.blocks.write", false)) {
            clusterService.addInitialStateBlock(TRIBE_WRITE_BLOCK);
        }
        blockIndicesWrite = settings.getAsArray("tribe.blocks.write.indices", Strings.EMPTY_ARRAY);
        if (settings.getAsBoolean("tribe.blocks.metadata", false)) {
            clusterService.addInitialStateBlock(TRIBE_METADATA_BLOCK);
        }
        blockIndicesMetadata = settings.getAsArray("tribe.blocks.metadata.indices", Strings.EMPTY_ARRAY);
        blockIndicesRead = settings.getAsArray("tribe.blocks.read.indices", Strings.EMPTY_ARRAY);
        for (Node node : nodes) {
            node.injector().getInstance(ClusterService.class).add(new TribeClusterStateListener(node));
        }
    }
    this.blockIndicesMetadata = blockIndicesMetadata;
    this.blockIndicesRead = blockIndicesRead;
    this.blockIndicesWrite = blockIndicesWrite;

    this.onConflict = settings.get("tribe.on_conflict", ON_CONFLICT_ANY);
}
 
Example 8
Source File: RestSnapshotsStatusAction.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
@Override
public void handleRequest(final RestRequest request, final RestChannel channel, final Client client) {
    String repository = request.param("repository", "_all");
    String[] snapshots = request.paramAsStringArray("snapshot", Strings.EMPTY_ARRAY);
    if (snapshots.length == 1 && "_all".equalsIgnoreCase(snapshots[0])) {
        snapshots = Strings.EMPTY_ARRAY;
    }
    SnapshotsStatusRequest snapshotsStatusResponse = snapshotsStatusRequest(repository).snapshots(snapshots);

    snapshotsStatusResponse.masterNodeTimeout(request.paramAsTime("master_timeout", snapshotsStatusResponse.masterNodeTimeout()));
    client.admin().cluster().snapshotsStatus(snapshotsStatusResponse, new RestToXContentListener<SnapshotsStatusResponse>(channel));
}
 
Example 9
Source File: RestRequest.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
public String[] paramAsStringArrayOrEmptyIfAll(String key) {
    String[] params = paramAsStringArray(key, Strings.EMPTY_ARRAY);
    if (Strings.isAllOrWildcard(params)) {
        return Strings.EMPTY_ARRAY;
    }
    return params;
}
 
Example 10
Source File: MappingMetaData.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
public ParsedVersion(String path, String versionType) {
    this.path = path;
    if (path == null) {
        this.pathElements = Strings.EMPTY_ARRAY;
        this.versionType = VersionType.INTERNAL;
    } else {
        this.versionType = VersionType.fromString(versionType);
        this.pathElements = Strings.delimitedListToStringArray(path, ".");
    }
}
 
Example 11
Source File: TranslogRecoveryPerformer.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
private static Engine.DeleteByQuery prepareDeleteByQuery(IndexQueryParserService queryParserService, MapperService mapperService, IndexAliasesService indexAliasesService, IndexCache indexCache, BytesReference source, @Nullable String[] filteringAliases, Engine.Operation.Origin origin, String... types) {
    long startTime = System.nanoTime();
    if (types == null) {
        types = Strings.EMPTY_ARRAY;
    }
    Query query;
    try {
        query = queryParserService.parseQuery(source).query();
    } catch (QueryParsingException ex) {
        // for BWC we try to parse directly the query since pre 1.0.0.Beta2 we didn't require a top level query field
        if (queryParserService.getIndexCreatedVersion().onOrBefore(Version.V_1_0_0_Beta2)) {
            try {
                XContentParser parser = XContentHelper.createParser(source);
                ParsedQuery parse = queryParserService.parse(parser);
                query = parse.query();
            } catch (Throwable t) {
                ex.addSuppressed(t);
                throw ex;
            }
        } else {
            throw ex;
        }
    }
    Query searchFilter = mapperService.searchFilter(types);
    if (searchFilter != null) {
        query = Queries.filtered(query, searchFilter);
    }

    Query aliasFilter = indexAliasesService.aliasFilter(filteringAliases);
    BitSetProducer parentFilter = mapperService.hasNested() ? indexCache.bitsetFilterCache().getBitSetProducer(Queries.newNonNestedFilter()) : null;
    return new Engine.DeleteByQuery(query, source, filteringAliases, aliasFilter, parentFilter, origin, startTime, types);
}
 
Example 12
Source File: DetailAnalyzeResponse.java    From Elasticsearch with Apache License 2.0 5 votes vote down vote up
public CharFilteredText(String name, String[] texts) {
    this.name = name;
    if (texts != null) {
        this.texts = texts;
    } else {
        this.texts = Strings.EMPTY_ARRAY;
    }
}
 
Example 13
Source File: RestHandlerUtils.java    From anomaly-detection with Apache License 2.0 5 votes vote down vote up
/**
 * Checks to see if the request came from Kibana, if so we want to return the UI Metadata from the document.
 * If the request came from the client then we exclude the UI Metadata from the search result.
 *
 * @param request rest request
 * @return instance of {@link org.elasticsearch.search.fetch.subphase.FetchSourceContext}
 */
public static FetchSourceContext getSourceContext(RestRequest request) {
    String userAgent = Strings.coalesceToEmpty(request.header("User-Agent"));
    if (!userAgent.contains(KIBANA_USER_AGENT)) {
        return new FetchSourceContext(true, Strings.EMPTY_ARRAY, UI_METADATA_EXCLUDE);
    } else {
        return null;
    }
}
 
Example 14
Source File: TypesExistsRequestBuilder.java    From Elasticsearch with Apache License 2.0 4 votes vote down vote up
/**
 * @param indices What indices to check for types
 */
public TypesExistsRequestBuilder(ElasticsearchClient client, TypesExistsAction action, String... indices) {
    super(client, action, new TypesExistsRequest(indices, Strings.EMPTY_ARRAY));
}
 
Example 15
Source File: IndicesSegmentsRequest.java    From Elasticsearch with Apache License 2.0 4 votes vote down vote up
public IndicesSegmentsRequest() {
    this(Strings.EMPTY_ARRAY);
}
 
Example 16
Source File: GetIndicesVersionRequest.java    From siren-join with GNU Affero General Public License v3.0 4 votes vote down vote up
public GetIndicesVersionRequest() {
  this(Strings.EMPTY_ARRAY);
}
 
Example 17
Source File: AbstractXContentTestCase.java    From crate with Apache License 2.0 4 votes vote down vote up
/**
 * Fields that have to be ignored when shuffling as part of testFromXContent
 */
protected String[] getShuffleFieldsExceptions() {
    return Strings.EMPTY_ARRAY;
}
 
Example 18
Source File: RestClearScrollAction.java    From Elasticsearch with Apache License 2.0 4 votes vote down vote up
public static String[] splitScrollIds(String scrollIds) {
    if (scrollIds == null) {
        return Strings.EMPTY_ARRAY;
    }
    return Strings.splitStringByCommaToArray(scrollIds);
}
 
Example 19
Source File: UpgradeStatusRequest.java    From Elasticsearch with Apache License 2.0 4 votes vote down vote up
public UpgradeStatusRequest() {
    this(Strings.EMPTY_ARRAY);
}
 
Example 20
Source File: RecoveryRequest.java    From crate with Apache License 2.0 4 votes vote down vote up
/**
 * Constructs a request for recovery information for all shards
 */
public RecoveryRequest() {
    this(Strings.EMPTY_ARRAY);
}