Skip to content

Synonyms API - GET Request #5

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
88 commits
Select commit Hold shift + click to select a range
2394f71
Add internal method to force connection close after request. (#96305)
stu-elastic May 24, 2023
1a1dcd9
Update serverless submodule update build trigger
mark-vieira May 24, 2023
ddd9024
Add CI pipeline for testing Elasticsearch changes in serverless
mark-vieira May 24, 2023
5bc7d26
Avoid stack overflow while parsing mapping (#95705)
mayya-sharipova May 24, 2023
085beea
Update branch triggering settings so GitHub pushes trigger build
mark-vieira May 24, 2023
870ca07
Enforce license for cross-cluster API key APIs (#96307)
ywangd May 25, 2023
905b8fe
Chunk profiling stacktrace response (#96340)
danielmitterdorfer May 25, 2023
d8e7373
Simplify node shutdown handling. (#96292)
idegtiarenko May 25, 2023
354992e
Make cluster info rest endpoint cancellable (#96327)
May 25, 2023
6208df0
Allow the removal of an in use template if there are other matching o…
gmarouli May 25, 2023
1762733
Stateless real-time GET (#93976)
pxsalehi May 25, 2023
f6e9bbf
Remove COMMON_PREFIX from MockLogAppender (#96331)
kingherc May 25, 2023
62bad38
PUT refactoring so service does not depend on response
carlosdelest May 25, 2023
e58094c
Initial GET action implementation
carlosdelest May 25, 2023
9d3bb2f
Added pagination
carlosdelest May 25, 2023
2a49ad9
Slightly better hot threads for transport workers (#96315)
DaveCTurner May 25, 2023
5717968
Add testing for GET
carlosdelest May 25, 2023
8b83636
Clean up `adjustSearchType` method (#96334)
jdconrad May 25, 2023
ea36a8b
Don't publish commit status to github for serverless checks
mark-vieira May 25, 2023
39c83d7
Universal Profiling: Remove cluster id from metrics mapping (#96335)
christos68k May 25, 2023
be6d5bb
Bump versions after 8.8.0 release
mark-vieira May 25, 2023
e0852a5
Prune changelogs after 8.8.0 release
mark-vieira May 25, 2023
3c3c14f
Introduce GlobalCheckpointSyncer interface (#96345)
DaveCTurner May 25, 2023
ecef641
Use assertBusy for task unregistration events (#96347)
pxsalehi May 25, 2023
3c5d96d
Support defining workflows restriction for API keys (#96215)
slobodanadamovic May 25, 2023
ac829ed
Enable skip methods on retrying inputstreams (#96337)
Tim-Brooks May 25, 2023
d68a2e0
[DOCS] Fixes a typo in the stop transform API docs (#96358)
abdonpijpelink May 25, 2023
d67a3ed
Update release notes for 8.8.0 release (#96354)
gmarouli May 25, 2023
9cee43b
Remove dependency license check for all org.elasticsearch (#96355)
rjernst May 25, 2023
08c0a9c
[Profiling] Add status API (#96272)
danielmitterdorfer May 26, 2023
fdabe7d
[Profiling] Rename lastprocessed into next_time in profiling-executab…
rockdaboot May 26, 2023
3808b53
Warn if allocation diverged from the desired allocation (#95458)
idegtiarenko May 26, 2023
244da06
Add `ingest` information to the cluster info endpoint (#96328)
May 26, 2023
41d4642
Dedicated internal user for DLM runtime tasks (#96253)
n1v0lg May 26, 2023
870ee28
Mute MultiNodesStatsTests#testMultipleNodes (#96375)
pxsalehi May 26, 2023
48c6547
remove unnecessary routing entry null checks (#96341)
pxsalehi May 26, 2023
77a80b0
Reject defining workflows restriction via file and Role API (#96304)
slobodanadamovic May 26, 2023
193e920
Use dynamic port range in testLoadsProxySettings (#96378)
pxsalehi May 26, 2023
b8a5704
[Profiling] Add comment to profiling-stackframes.json (#96384)
rockdaboot May 26, 2023
3228058
Adding manage_dlm privilege (#95512)
masseyke May 26, 2023
9649ee0
add analytics_collections to ent search usage test (#96385)
May 26, 2023
2b0d6e6
Introduce CancellableFanOut (#96373)
DaveCTurner May 26, 2023
d5f9e11
Update tsds-index-settings.asciidoc (#96366)
martijnvg May 26, 2023
9aead84
Fixing DataLifecycleServiceIT.testAutomaticForceMerge() using a Stubb…
masseyke May 26, 2023
860ccfd
Ignoring DataLifecycleServiceIT.testAutomaticForceMerge (#96395)
masseyke May 26, 2023
a71e988
[Test] Include DLM actions only when feature flag is enabled (#96118)
ywangd May 26, 2023
e5e2a04
REST spec and YAML tests for cross-cluster API key APIs (#96339)
ywangd May 26, 2023
f183d5c
Speed up SharedBytes.IO (#96388)
original-brownbear May 28, 2023
06f0276
Convert ThreadPool stats objects to records (#96400)
May 29, 2023
7eaa868
Reduce indirection in AbstractRefCounted (#96403)
DaveCTurner May 29, 2023
0e95bb4
Reject OPTIONS requests with a body (#96357)
albertzaharovits May 29, 2023
dae0c6f
Remove fair version of KeyedLock (#96411)
original-brownbear May 29, 2023
0cf80f4
Move global checkpoint sync to write threadpool (#96364)
Tim-Brooks May 29, 2023
2513104
Improve cancellability in TransportTasksAction (#96279)
DaveCTurner May 30, 2023
23a592d
[Profiling] Set index:true for Symbolization.next_time (#96417)
rockdaboot May 30, 2023
815190a
Move the registration of the aggregation collector manager to SearchC…
iverase May 30, 2023
4ca12c1
Require DLM enabled in the mixed-cluster QA cluster (#96391)
andreidan May 30, 2023
16aba06
[DOCS] Make 2028 dims 'experimental' warning inline (#96369)
abdonpijpelink May 30, 2023
94ed4ca
[Test] Add missing feature flag checks for RCS 2.0 tests (#96424)
slobodanadamovic May 30, 2023
651ec81
Promptly fail recovery from snapshot (#96421)
DaveCTurner May 30, 2023
e5111e3
Make list-tasks API cancellable (#96283)
DaveCTurner May 30, 2023
17ff9f0
Adding `data_lifecycle` to the `_xpack/usage` API (#96177)
masseyke May 30, 2023
dd4641d
AwaitsFix for #96427
DaveCTurner May 30, 2023
433ce88
Rank_feature field null_value test and small edits (#96392)
mayya-sharipova May 30, 2023
b7bbc19
Test fix: add dlm usage as a non-operator action (#96428)
gmarouli May 30, 2023
1f8169d
Mention DLM in ignored docs test comments (#96422)
n1v0lg May 30, 2023
66a951e
Fix tchar pattern in RestRequest (#96406)
pgomulka May 30, 2023
494847b
Remove unnecessary reroute from tests (#96435)
idegtiarenko May 30, 2023
6cb97a5
Allow unsigned long field to use decay functions (#96394)
jdconrad May 30, 2023
ad463c9
Fix race in testCancelledRecoveryAbortsDownloadPromptly (#96431)
DaveCTurner May 30, 2023
31044b9
Count refs to index commit held by snapshot (#96426)
DaveCTurner May 30, 2023
0a7bb64
Fix recovery permit exhaustion message (#96336)
volodk85 May 30, 2023
1ae63ac
Optimize KeyedLock and related concurrency primitives (#96372)
original-brownbear May 30, 2023
0b8b5aa
Revert "Temporarily disable retries in docker build tasks (#96256)" (…
mark-vieira May 30, 2023
83bfcc6
Disallow derived cross-cluster API keys (#96401)
ywangd May 31, 2023
47c70f9
Format message only when debug is enabled (#96437)
idegtiarenko May 31, 2023
e5768d9
Upgrade Lucene to a 9.7.0 snapshot (#96433)
javanna May 31, 2023
39b7b5e
Synonym Mgmnt API: PUT request (#95895)
carlosdelest May 31, 2023
b7d9442
Add known issue docs for #95114 (#96448)
DaveCTurner May 31, 2023
224d367
Optimize SparseFileTracker (#96379)
original-brownbear May 31, 2023
856a244
Reduce overhead in blob cache service get (#96399)
henningandersen May 31, 2023
e6031d8
Port DLM permissions test to internal REST test style (#96434)
n1v0lg May 31, 2023
4617095
Ignore BlobStoreIndexShardSnapshot#indexVersion (#96450)
DaveCTurner May 31, 2023
9a8bb61
Known-issue docs for #95454 (#96459)
DaveCTurner May 31, 2023
b70a1f6
Merge remote-tracking branch 'origin/main' into carlosdelest/synonyms…
carlosdelest May 31, 2023
e2c3045
WIP
carlosdelest May 31, 2023
cdf05a0
Removed SynonymsSet class
carlosdelest May 31, 2023
a69457c
Remove changelog YAML
carlosdelest May 31, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
{
"synonyms.get": {
"documentation": {
"url": "https://www.elastic.co/guide/en/elasticsearch/reference/master/get-synonyms.html",
"description": "Retrieves a synonym set"
},
"stability": "experimental",
"visibility": "feature_flag",
"feature_flag": "es.synonyms_feature_flag_enabled",
"headers": {
"accept": [
"application/json"
]
},
"url": {
"paths": [
{
"path": "/_synonyms/{synonyms_set}",
"methods": [
"GET"
],
"parts": {
"synonyms_set": {
"type": "string",
"description": "The name of the synonyms set to be retrieved"
}
}
}
]
},
"params": {
"from": {
"type": "int",
"description": "Starting offset (default: 0)"
},
"size": {
"type": "int",
"description": "specifies a max number of results to get"
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
setup:
- do:
synonyms.put:
synonyms_set: test-get-synonyms
body:
synonyms_set:
- synonyms: "hello, hi"
id: "test-id-1"
- synonyms: "bye => goodbye"
id: "test-id-2"
- synonyms: "test => check"
id: "test-id-3"

---
"Get synonyms set":
- skip:
version: " - 8.8.99"
reason: Introduced in 8.9.0
- do:
synonyms.get:
synonyms_set: test-get-synonyms

- match:
count: 3
- match:
synonyms_set:
- synonyms: "hello, hi"
id: "test-id-1"
- synonyms: "bye => goodbye"
id: "test-id-2"
- synonyms: "test => check"
id: "test-id-3"

---
"Get synonyms set - not found":
- skip:
version: " - 8.8.99"
reason: Introduced in 8.9.0
- do:
catch: missing
synonyms.get:
synonyms_set: unknown-synonym-set

---
"Pagination - size":
- skip:
version: " - 8.8.99"
reason: Introduced in 8.9.0
- do:
synonyms.get:
synonyms_set: test-get-synonyms
size: 2

- match:
count: 3
- match:
synonyms_set:
- synonyms: "hello, hi"
id: "test-id-1"
- synonyms: "bye => goodbye"
id: "test-id-2"

---
"Pagination - from":
- skip:
version: " - 8.8.99"
reason: Introduced in 8.9.0
- do:
synonyms.get:
synonyms_set: test-get-synonyms
from: 1

- match:
count: 3
- match:
synonyms_set:
- synonyms: "bye => goodbye"
id: "test-id-2"
- synonyms: "test => check"
id: "test-id-3"
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,9 @@
import org.elasticsearch.action.support.AutoCreateIndex;
import org.elasticsearch.action.support.DestructiveOperations;
import org.elasticsearch.action.support.TransportAction;
import org.elasticsearch.action.synonyms.GetSynonymsAction;
import org.elasticsearch.action.synonyms.PutSynonymsAction;
import org.elasticsearch.action.synonyms.TransportGetSynonymsAction;
import org.elasticsearch.action.synonyms.TransportPutSynonymsAction;
import org.elasticsearch.action.termvectors.MultiTermVectorsAction;
import org.elasticsearch.action.termvectors.TermVectorsAction;
Expand Down Expand Up @@ -434,6 +436,7 @@
import org.elasticsearch.rest.action.search.RestMultiSearchAction;
import org.elasticsearch.rest.action.search.RestSearchAction;
import org.elasticsearch.rest.action.search.RestSearchScrollAction;
import org.elasticsearch.rest.action.synonyms.RestGetSynonymsAction;
import org.elasticsearch.rest.action.synonyms.RestPutSynonymsAction;
import org.elasticsearch.synonyms.SynonymsAPI;
import org.elasticsearch.tasks.Task;
Expand Down Expand Up @@ -779,6 +782,7 @@ public <Request extends ActionRequest, Response extends ActionResponse> void reg
// Synonyms
if (SynonymsAPI.isEnabled()) {
actions.register(PutSynonymsAction.INSTANCE, TransportPutSynonymsAction.class);
actions.register(GetSynonymsAction.INSTANCE, TransportGetSynonymsAction.class);
}

return unmodifiableMap(actions.getRegistry());
Expand Down Expand Up @@ -992,6 +996,7 @@ public void initRestHandlers(Supplier<DiscoveryNodes> nodesInCluster) {
// Synonyms
if (SynonymsAPI.isEnabled()) {
registerHandler.accept(new RestPutSynonymsAction());
registerHandler.accept(new RestGetSynonymsAction());
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

package org.elasticsearch.action.synonyms;

import org.elasticsearch.action.ActionRequest;
import org.elasticsearch.action.ActionRequestValidationException;
import org.elasticsearch.action.ActionResponse;
import org.elasticsearch.action.ActionType;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.synonyms.SynonymsManagementAPIService;
import org.elasticsearch.synonyms.SynonymsSet;
import org.elasticsearch.xcontent.ToXContentObject;
import org.elasticsearch.xcontent.XContentBuilder;

import java.io.IOException;
import java.util.Objects;

import static org.elasticsearch.action.ValidateActions.addValidationError;

public class GetSynonymsAction extends ActionType<GetSynonymsAction.Response> {

public static final GetSynonymsAction INSTANCE = new GetSynonymsAction();
public static final String NAME = "cluster:admin/synonyms/get";

public GetSynonymsAction() {
super(NAME, Response::new);
}

public static class Request extends ActionRequest {
private final String SynonymsSetId;
private final int from;
private final int size;

public Request(StreamInput in) throws IOException {
super(in);
this.SynonymsSetId = in.readString();
this.from = in.readInt();
this.size = in.readInt();
}

public Request(String SynonymsSetId, int from, int size) {
Objects.requireNonNull(SynonymsSetId, "Synonym set ID cannot be null");
this.SynonymsSetId = SynonymsSetId;
this.from = from;
this.size = size;
}

@Override
public ActionRequestValidationException validate() {
ActionRequestValidationException validationException = null;
if (from < 0) {
validationException = addValidationError("from must be a positive integer", validationException);
}
if (size < 0) {
validationException = addValidationError("size must be a positive integer", validationException);
}
return validationException;
}

@Override
public void writeTo(StreamOutput out) throws IOException {
super.writeTo(out);
out.writeString(SynonymsSetId);
out.writeInt(from);
out.writeInt(size);
}

public String synonymsSetId() {
return SynonymsSetId;
}

public int from() {
return from;
}

public int size() {
return size;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Request request = (Request) o;
return from == request.from && size == request.size && Objects.equals(SynonymsSetId, request.SynonymsSetId);
}

@Override
public int hashCode() {
return Objects.hash(SynonymsSetId, from, size);
}
}

public static class Response extends ActionResponse implements ToXContentObject {

private final SynonymsManagementAPIService.SynonymsSetResult synonymsSetResults;

public Response(StreamInput in) throws IOException {
super(in);
this.synonymsSetResults = new SynonymsManagementAPIService.SynonymsSetResult(in.readLong(), new SynonymsSet(in));
}

public Response(SynonymsManagementAPIService.SynonymsSetResult synonymsSetResult) {
super();
Objects.requireNonNull(synonymsSetResult, "Synonyms set result must not be null");
this.synonymsSetResults = synonymsSetResult;
}

@Override
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
builder.startObject();
{
builder.field("count", synonymsSetResults.totalSynonymRules());
synonymsSetResults.synonymsSet().toXContent(builder, params);
}
builder.endObject();

return builder;
}

@Override
public void writeTo(StreamOutput out) throws IOException {
out.writeLong(synonymsSetResults.totalSynonymRules());
synonymsSetResults.synonymsSet().writeTo(out);
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Response response = (Response) o;
return Objects.equals(this.synonymsSetResults, response.synonymsSetResults);
}

@Override
public int hashCode() {
return Objects.hash(synonymsSetResults);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.elasticsearch.common.xcontent.StatusToXContentObject;
import org.elasticsearch.common.xcontent.XContentHelper;
import org.elasticsearch.rest.RestStatus;
import org.elasticsearch.synonyms.SynonymsManagementAPIService;
import org.elasticsearch.synonyms.SynonymsSet;
import org.elasticsearch.xcontent.ToXContent;
import org.elasticsearch.xcontent.XContentBuilder;
Expand Down Expand Up @@ -103,14 +104,14 @@ public int hashCode() {

public static class Response extends ActionResponse implements StatusToXContentObject {

private final Result result;
private final SynonymsManagementAPIService.UpdateSynonymsResult result;
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did some refactoring for PUT. It didn't feel right that the SynonymsManagementAPIService depended on the request, so I defined the response enum in the SynonymsManagementAPIService and the response now uses it.


public Response(StreamInput in) throws IOException {
super(in);
this.result = in.readEnum((Result.class));
this.result = in.readEnum((SynonymsManagementAPIService.UpdateSynonymsResult.class));
}

public Response(Result result) {
public Response(SynonymsManagementAPIService.UpdateSynonymsResult result) {
super();
Objects.requireNonNull(result, "Result must not be null");
this.result = result;
Expand Down Expand Up @@ -151,9 +152,5 @@ public int hashCode() {
return Objects.hash(result);
}

public enum Result {
CREATED,
UPDATED
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

package org.elasticsearch.action.synonyms;

import org.elasticsearch.action.ActionListener;
import org.elasticsearch.action.support.ActionFilters;
import org.elasticsearch.action.support.HandledTransportAction;
import org.elasticsearch.client.internal.Client;
import org.elasticsearch.common.inject.Inject;
import org.elasticsearch.synonyms.SynonymsManagementAPIService;
import org.elasticsearch.tasks.Task;
import org.elasticsearch.transport.TransportService;

public class TransportGetSynonymsAction extends HandledTransportAction<GetSynonymsAction.Request, GetSynonymsAction.Response> {

private final SynonymsManagementAPIService synonymsManagementAPIService;

@Inject
public TransportGetSynonymsAction(TransportService transportService, ActionFilters actionFilters, Client client) {
super(GetSynonymsAction.NAME, transportService, actionFilters, GetSynonymsAction.Request::new);

this.synonymsManagementAPIService = new SynonymsManagementAPIService(client);
}

@Override
protected void doExecute(Task task, GetSynonymsAction.Request request, ActionListener<GetSynonymsAction.Response> listener) {
synonymsManagementAPIService.getSynonymsSet(
request.synonymsSetId(),
request.from(),
request.size(),
listener.map(GetSynonymsAction.Response::new)
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ public TransportPutSynonymsAction(TransportService transportService, ActionFilte

@Override
protected void doExecute(Task task, PutSynonymsAction.Request request, ActionListener<PutSynonymsAction.Response> listener) {
synonymsManagementAPIService.putSynonymsset(request.synonymsSetId(), request.synonymsset(), listener);
synonymsManagementAPIService.putSynonymsSet(
request.synonymsSetId(),
request.synonymsset(),
listener.map(PutSynonymsAction.Response::new)
);
}
}
Loading