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

[FEATURE] Add native JSON support #331

Closed
dblock opened this issue Jun 12, 2023 · 7 comments
Closed

[FEATURE] Add native JSON support #331

dblock opened this issue Jun 12, 2023 · 7 comments
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@dblock
Copy link
Member

dblock commented Jun 12, 2023

Is your feature request related to a problem?

Ingesting a document today requires supplying it as an IoReader. Starting with an example in https://xeiaso.net/blog/elasticsearch:

data, err := json.Marshal(esEntry)
if err != nil {
	log.Fatalf("failed to marshal entry: %v", err)
}

resp, err := es.Index("site-search-kb", bytes.NewBuffer(data), es.Index.WithDocumentID(entry.ID))

Ugh.

What solution would you like?

Automatically marshal objects to/from JSON. Starting with the canonical example from https://go.dev/blog/json I think I want something that doesn't say "IoStreams" everywhere.

m := Message{"Alice", "Hello", 1294706395881547000}
es.Index("site-search-kb", m, es.Index.WithDocumentID(1))

Do you have any additional context?

Came from https://xeiaso.net/blog/elasticsearch

@dblock dblock added enhancement New feature or request untriaged labels Jun 12, 2023
@dblock
Copy link
Member Author

dblock commented Jun 12, 2023

@Jakob3xD would love your thoughts!

@dblock dblock changed the title [FEATURE] Native JSON support [FEATURE] Add native JSON support Jun 12, 2023
@Jakob3xD
Copy link
Collaborator

Is a valid feature. Should be relative simple to implement, by making the requests bodys given to the function as arg an interface and the Marshal it.

@dblock dblock added help wanted Extra attention is needed and removed untriaged labels Jun 13, 2023
@YuyaAbo
Copy link
Contributor

YuyaAbo commented Jun 26, 2023

I went through the code to understand the Issue and found opensearchutil.NewJSONReader. Is this sufficient to resolve the Issue? Is it enough to resolve the Issue or is there some functionality missing?

This utility function seems to be used as follows.

doc := struct {
Title string `json:"title"`
}{Title: "Foo Bar"}
res, err = client.Index("test", opensearchutil.NewJSONReader(&doc), client.Index.WithRefresh("true"))
if err != nil {
t.Fatalf("Error getting response: %s", err)
}

@dblock
Copy link
Member Author

dblock commented Jun 26, 2023

@YuyaAbo Thank you!

  1. Can this be somehow automatic? In this case this would be a feature request.
  2. Do we document this anywhere? Either way we should document this in the user guide, then we can close this. Would you like to help?

@YuyaAbo
Copy link
Contributor

YuyaAbo commented Jun 28, 2023

@dblock Yes, it would certainly be a useful addition if it could be automated.

I will add an introduction to opensearchutil.NewJSONReader to the user guide. I will send a PR later.

We will leave this issue as is for the purpose of adding functionality.

@tannerjones4075
Copy link
Contributor

Should this issue be closed? #341 seems to have committed a merge request to add the functionality unless I am mistaken.

@dblock
Copy link
Member Author

dblock commented Oct 3, 2023

Yes, closing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

4 participants