-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Implement _source parameter on action and doc lines. #4339
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
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
6dac438
Implement _source parameter on action and doc lines.
codebrain 320bed9
Update Source type to Union<bool, ISourceFilter>
codebrain a2fb17d
Include _source parameter in action and body parts of the bulk request.
codebrain 1049271
Add the get property, and provide a method to deserialise the get pro…
codebrain 7f93873
Model changes to bulk example as line changes to track differences
codebrain bfbdd7c
Use JObject modifier in examples for bulk requests
codebrain 436dad5
Add unit test for get response
codebrain 186f7ca
Remove redundant method
codebrain f31b194
Generate asciidoc example
codebrain File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
50 changes: 50 additions & 0 deletions
50
examples/Docs/BulkPage/8cd00a3aba7c3c158277bc032aac2830.asciidoc
This file contains hidden or 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,50 @@ | ||
//// | ||
IMPORTANT NOTE | ||
============== | ||
This file is generated from method Line405 in https://github.com/elastic/elasticsearch-net/tree/master/src/Examples/Examples/Docs/BulkPage.cs#L47-L113. | ||
If you wish to submit a PR to change this example, please change the source method above | ||
and run dotnet run -- asciidoc in the ExamplesGenerator project directory. | ||
//// | ||
[source, csharp] | ||
---- | ||
var bulkResponse = client.Bulk(b => b | ||
.Update<object>(u => u | ||
.Index("index1") | ||
.Id("1") | ||
.RetriesOnConflict(3) | ||
.Doc(new { field = "value" }) | ||
) | ||
.Update<object>(u => u | ||
.Index("index1") | ||
.Id("0") | ||
.RetriesOnConflict(3) | ||
.Script(s => s | ||
.Source("ctx._source.counter += params.param1") | ||
.Lang("painless") | ||
.Params(d => d | ||
.Add("param1", 1) | ||
) | ||
) | ||
.Upsert(new { counter = 1 }) | ||
) | ||
.Update<object>(u => u | ||
.Index("index1") | ||
.Id("2") | ||
.RetriesOnConflict(3) | ||
.Doc(new { field = "value" }) | ||
.DocAsUpsert(true) | ||
) | ||
.Update<object>(u => u | ||
.Index("index1") | ||
.Id("3") | ||
.Source(true) | ||
.Doc(new { field = "value" }) | ||
) | ||
.Update<object>(u => u | ||
.Index("index1") | ||
.Id("4") | ||
.Source(true) | ||
.Doc(new { field = "value" }) | ||
) | ||
); | ||
---- |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
70 changes: 70 additions & 0 deletions
70
tests/Tests/Document/Multiple/Bulk/BulkSourceDeserialize.cs
This file contains hidden or 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,70 @@ | ||
using System; | ||
using System.Text; | ||
using Elastic.Xunit.XunitPlumbing; | ||
using Elasticsearch.Net; | ||
using FluentAssertions; | ||
using Nest; | ||
using Tests.Core.Extensions; | ||
|
||
namespace Tests.Document.Multiple.Bulk | ||
{ | ||
public class BulkSourceDeserialize | ||
{ | ||
[U] | ||
public void CanDeserialize() | ||
{ | ||
var json = @"{ | ||
""took"": 61, | ||
""errors"": false, | ||
""items"": [{ | ||
""update"": { | ||
""_index"": ""test"", | ||
""_type"": ""_doc"", | ||
""_id"": ""1"", | ||
""_version"": 2, | ||
""result"": ""updated"", | ||
""_shards"": { | ||
""total"": 2, | ||
""successful"": 1, | ||
""failed"": 0 | ||
}, | ||
""_seq_no"": 3, | ||
""_primary_term"": 1, | ||
""get"": { | ||
""_seq_no"": 3, | ||
""_primary_term"": 1, | ||
""found"": true, | ||
""_source"": { | ||
""field1"": ""value1"", | ||
""field2"": ""value2"" | ||
} | ||
}, | ||
""status"": 200 | ||
} | ||
}] | ||
}"; | ||
|
||
var pool = new SingleNodeConnectionPool(new Uri("http://localhost:9200")); | ||
|
||
var connection = new InMemoryConnection(Encoding.UTF8.GetBytes(json)); | ||
var settings = new ConnectionSettings(pool, connection); | ||
var client = new ElasticClient(settings); | ||
|
||
var bulkResponse = client.Bulk(r => r); | ||
|
||
bulkResponse.ShouldBeValid(); | ||
|
||
var simpleObject = bulkResponse.Items[0].GetResponse<SimpleObject>(); | ||
|
||
simpleObject.Found.Should().BeTrue(); | ||
simpleObject.Source.field1.Should().Be("value1"); | ||
simpleObject.Source.field2.Should().Be("value2"); | ||
} | ||
|
||
private class SimpleObject | ||
{ | ||
public string field1 { get; set; } | ||
public string field2 { get; set; } | ||
} | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.