forked from elastic/elasticsearch
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Get Source API to the HLRC (elastic#50885)
Relates to elastic#47678
- Loading branch information
1 parent
157b352
commit 814d5fb
Showing
11 changed files
with
582 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
126 changes: 126 additions & 0 deletions
126
client/rest-high-level/src/main/java/org/elasticsearch/client/core/GetSourceRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
/* | ||
* Licensed to Elasticsearch under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
package org.elasticsearch.client.core; | ||
|
||
import org.elasticsearch.client.Validatable; | ||
import org.elasticsearch.common.xcontent.ToXContentObject; | ||
import org.elasticsearch.common.xcontent.XContentBuilder; | ||
import org.elasticsearch.search.fetch.subphase.FetchSourceContext; | ||
|
||
import java.io.IOException; | ||
|
||
public final class GetSourceRequest implements Validatable, ToXContentObject { | ||
private String routing; | ||
private String preference; | ||
|
||
private boolean refresh = false; | ||
private boolean realtime = true; | ||
|
||
private FetchSourceContext fetchSourceContext; | ||
|
||
private String index; | ||
private String id; | ||
|
||
public GetSourceRequest(String index, String id) { | ||
this.index = index; | ||
this.id = id; | ||
} | ||
|
||
/** | ||
* Controls the shard routing of the request. Using this value to hash the shard | ||
* and not the id. | ||
*/ | ||
public GetSourceRequest routing(String routing) { | ||
if (routing != null && routing.length() == 0) { | ||
this.routing = null; | ||
} else { | ||
this.routing = routing; | ||
} | ||
return this; | ||
} | ||
|
||
/** | ||
* Sets the preference to execute the search. Defaults to randomize across shards. Can be set to | ||
* {@code _local} to prefer local shards or a custom value, which guarantees that the same order | ||
* will be used across different requests. | ||
*/ | ||
public GetSourceRequest preference(String preference) { | ||
this.preference = preference; | ||
return this; | ||
} | ||
|
||
/** | ||
* Should a refresh be executed before this get operation causing the operation to | ||
* return the latest value. Note, heavy get should not set this to {@code true}. Defaults | ||
* to {@code false}. | ||
*/ | ||
public GetSourceRequest refresh(boolean refresh) { | ||
this.refresh = refresh; | ||
return this; | ||
} | ||
|
||
public GetSourceRequest realtime(boolean realtime) { | ||
this.realtime = realtime; | ||
return this; | ||
} | ||
|
||
/** | ||
* Allows setting the {@link FetchSourceContext} for this request, controlling if and how _source should be returned. | ||
* Note, the {@code fetchSource} field of the context must be set to {@code true}. | ||
*/ | ||
|
||
public GetSourceRequest fetchSourceContext(FetchSourceContext context) { | ||
this.fetchSourceContext = context; | ||
return this; | ||
} | ||
|
||
@Override | ||
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException { | ||
return null; | ||
} | ||
|
||
public String index() { | ||
return index; | ||
} | ||
|
||
public String id() { | ||
return id; | ||
} | ||
|
||
public String routing() { | ||
return routing; | ||
} | ||
|
||
public String preference() { | ||
return preference; | ||
} | ||
|
||
public boolean refresh() { | ||
return refresh; | ||
} | ||
|
||
public boolean realtime() { | ||
return realtime; | ||
} | ||
|
||
public FetchSourceContext fetchSourceContext() { | ||
return fetchSourceContext; | ||
} | ||
} |
47 changes: 47 additions & 0 deletions
47
client/rest-high-level/src/main/java/org/elasticsearch/client/core/GetSourceResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/* | ||
* Licensed to Elasticsearch under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
package org.elasticsearch.client.core; | ||
|
||
import org.elasticsearch.common.xcontent.XContentParser; | ||
|
||
import java.io.IOException; | ||
import java.util.Map; | ||
|
||
public final class GetSourceResponse { | ||
|
||
private final Map<String, Object> source; | ||
|
||
public GetSourceResponse(Map<String, Object> source) { | ||
this.source = source; | ||
} | ||
|
||
public static GetSourceResponse fromXContent(XContentParser parser) throws IOException { | ||
return new GetSourceResponse(parser.map()); | ||
} | ||
|
||
public Map<String, Object> getSource() { | ||
return this.source; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return source.toString(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.