Skip to content
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

Added guide for using raw JSON REST requests with low-level client. #406

Merged
merged 3 commits into from
Nov 13, 2023

Conversation

Djcarrillo6
Copy link
Contributor

Description

Adds a new guide that demonstrates how to interact with the OpenSearch REST API using the OpenSearch .NET low-level client by executing raw JSON REST requests. It covers a number of operations such as setting up an OpenSearch instance, indexing document data, and executing CRUD operations (CREATE, READ, UPDATE and DELETE) on documents in the index.

Issues Resolved

Resolves issue 403

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.

Copy link
Member

@dblock dblock left a comment

Choose a reason for hiding this comment

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

Good start.

  1. Remove any usage of higher level classes that aren't raw request/response.
  2. Write a working sample and put it into samples so we can make sure this code works.

guides/using-json-rest-requests.md Outdated Show resolved Hide resolved
guides/using-json-rest-requests.md Outdated Show resolved Hide resolved
guides/using-json-rest-requests.md Outdated Show resolved Hide resolved
@Djcarrillo6
Copy link
Contributor Author

Djcarrillo6 commented Oct 23, 2023

Good start.

  1. Remove any usage of higher level classes that aren't raw request/response.
  2. Write a working sample and put it into samples so we can make sure this code works.

@dblock @Xtansia If I'm not mistaken, this .NET client repo does not currently have a "samples" directory like the Python client does. Should I create that new directory here and place my working sample in that location? Or should I just attach the sample in the same "guides" directory where the MD files live?

@dblock
Copy link
Member

dblock commented Oct 24, 2023

@dblock @Xtansia If I'm not mistaken, this .NET client repo does not currently have a "samples" directory like the Python client does. Should I create that new directory here and place my working sample in that location? Or should I just attach the sample in the same "guides" directory where the MD files live?

Please create one!

@Djcarrillo6 Djcarrillo6 force-pushed the feat/guides-json branch 2 times, most recently from e4d1de2 to 9991b1d Compare October 25, 2023 02:48
@Djcarrillo6
Copy link
Contributor Author

@dblock I added the new sample directory and added a working sample for my guide. I also change the name of guide file to match what the Python client guide used.

Copy link
Member

@dblock dblock left a comment

Choose a reason for hiding this comment

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

Looks better! Would format text a bit in json.md.

Add a link from USERS_GUIDE to this guide too?

Will leave this for a proper CR for @Xtansia or someone who's a maintainer here. I would check that these examples properly throw errors.

@Djcarrillo6
Copy link
Contributor Author

Hey @Xtansia, would you like me to add a link to this guide in the USER_GUIDE.md file? If so, which section to you think is best with respect to the guide's link placement.

Copy link
Collaborator

@Xtansia Xtansia left a comment

Choose a reason for hiding this comment

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

@Djcarrillo6 A few points:

@Djcarrillo6
Copy link
Contributor Author

@Djcarrillo6 A few points:

@Xtansia what would adding the sample to a new project entail? Could I just add the sample file to the src/OpenSearch.Net directory?

@Djcarrillo6 A few points:

@Xtansia Can you detail how would I would correctly add this sample to a new project within the repo?

@Xtansia
Copy link
Collaborator

Xtansia commented Nov 2, 2023

@Djcarrillo6 You can create and add a new project with the dotnet CLI:

dotnet new console -o samples/Samples
dotnet sln add samples/Samples

USER_GUIDE.md Outdated Show resolved Hide resolved
samples/Samples/Program.cs Outdated Show resolved Hide resolved
samples/Samples/Samples.csproj Show resolved Hide resolved
samples/Samples/Samples.csproj Outdated Show resolved Hide resolved
guides/json.md Show resolved Hide resolved
samples/Samples/Samples.csproj Outdated Show resolved Hide resolved
samples/Samples/Program.cs Outdated Show resolved Hide resolved
USER_GUIDE.md Outdated Show resolved Hide resolved
guides/json.md Outdated Show resolved Hide resolved
Copy link
Member

@dblock dblock left a comment

Choose a reason for hiding this comment

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

Let's make a subfolder for the sample and call it "RawJsonSample"?

number_of_shards = 4
}
}
};
Copy link
Member

Choose a reason for hiding this comment

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

Is there a JSON/string version of this? Not sure what's best for this example, maybe both?

@Djcarrillo6
Copy link
Contributor Author

@Xtansia I added the new folder structure & converted the sample to use raw JSON to match the guide implementation as @dblock requested.

Copy link
Collaborator

@Xtansia Xtansia left a comment

Choose a reason for hiding this comment

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

If you're using a string body, you should use PostData.String rather than PostData.Serializable. The guide examples need to be updated to match the sample code. It'd be good to add a section to the guide informing users about the different types of PostData they can use with examples.

Signed-off-by: Djcarrillo6 <[email protected]>

Added sample for using raw JSON REST requests with low-level client.

Signed-off-by: Djcarrillo6 <[email protected]>

Added sample for using raw JSON REST requests with low-level client opensearch-project#2

Signed-off-by: Djcarrillo6 <[email protected]>

Created new samples project & PR review changes.

Signed-off-by: Djcarrillo6 <[email protected]>

Aligned action examples with Python guide.

Signed-off-by: Djcarrillo6 <[email protected]>

PR change requests.

Signed-off-by: Djcarrillo6 <[email protected]>

Changed to raw JSON in sample code.

Signed-off-by: Djcarrillo6 <[email protected]>

Added new section to the guide for using PostData.Serializable()

Signed-off-by: Djcarrillo6 <[email protected]>
@Djcarrillo6
Copy link
Contributor Author

If you're using a string body, you should use PostData.String rather than PostData.Serializable. The guide examples need to be updated to match the sample code. It'd be good to add a section to the guide informing users about the different types of PostData they can use with examples.

@Xtansia I made the change to PostData.String and added a section to the guide informing users about the different PostData they can use with examples. Let me know if you'd like anything changed

@Djcarrillo6 Djcarrillo6 requested a review from Xtansia November 12, 2023 01:31
@Xtansia Xtansia merged commit 1924be9 into opensearch-project:main Nov 13, 2023
34 of 36 checks passed
@dblock
Copy link
Member

dblock commented Nov 13, 2023

Looking at how this is done in the .NET client, would aliasing LowLevel to .http make sense to make the API more digestable? Similar to opensearch-project/opensearch-py#544.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants