-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Forward port of #2231
- Loading branch information
Showing
15 changed files
with
237 additions
and
24 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
71 changes: 71 additions & 0 deletions
71
docs/query-dsl/span/field-masking/span-field-masking-usage.asciidoc
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,71 @@ | ||
:ref_current: https://www.elastic.co/guide/en/elasticsearch/reference/2.3 | ||
|
||
:github: https://github.com/elastic/elasticsearch-net | ||
|
||
:nuget: https://www.nuget.org/packages | ||
|
||
//// | ||
IMPORTANT NOTE | ||
============== | ||
This file has been generated from https://github.com/elastic/elasticsearch-net/tree/2.x/src/Tests/QueryDsl/Span/FieldMasking/SpanFieldMaskingUsageTests.cs. | ||
If you wish to submit a PR for any spelling mistakes, typos or grammatical errors for this file, | ||
please modify the original csharp file found at the link and submit the PR with that change. Thanks! | ||
//// | ||
|
||
[[span-field-masking-usage]] | ||
== Span Field Masking Usage | ||
|
||
=== Fluent DSL Example | ||
|
||
[source,csharp] | ||
---- | ||
q | ||
.SpanFieldMasking(c => c | ||
.Name("named_query") | ||
.Boost(1.1) | ||
.Field(p => p.Name) | ||
.Query(sq=>sq | ||
.SpanTerm(st=>st.Field(p=>p.Description).Value("dolorem")) | ||
) | ||
) | ||
---- | ||
|
||
=== Object Initializer Syntax Example | ||
|
||
[source,csharp] | ||
---- | ||
new SpanFieldMaskingQuery | ||
{ | ||
Name = "named_query", | ||
Boost = 1.1, | ||
Field = Infer.Field<Project>(p => p.Name), | ||
Query = new SpanQuery | ||
{ | ||
SpanTerm = new SpanTermQuery | ||
{ | ||
Field = Infer.Field<Project>(p => p.Description), | ||
Value = "dolorem" | ||
} | ||
} | ||
} | ||
---- | ||
|
||
[source,javascript] | ||
.Example json output | ||
---- | ||
{ | ||
"field_masking_span": { | ||
"_name": "named_query", | ||
"boost": 1.1, | ||
"field": "name", | ||
"query": { | ||
"span_term": { | ||
"description": { | ||
"value": "dolorem" | ||
} | ||
} | ||
} | ||
} | ||
} | ||
---- | ||
|
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
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
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
49 changes: 49 additions & 0 deletions
49
src/Nest/QueryDsl/Span/FieldMasking/SpanFieldMaskingQuery.cs
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,49 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Linq.Expressions; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using Newtonsoft.Json; | ||
|
||
namespace Nest | ||
{ | ||
[JsonObject(MemberSerialization = MemberSerialization.OptIn)] | ||
[JsonConverter(typeof(ReadAsTypeJsonConverter<SpanFieldMaskingQueryDescriptor<object>>))] | ||
public interface ISpanFieldMaskingQuery : ISpanSubQuery | ||
{ | ||
[JsonProperty("field")] | ||
Field Field { get; set; } | ||
|
||
[JsonProperty("query")] | ||
ISpanQuery Query { get; set; } | ||
} | ||
|
||
public class SpanFieldMaskingQuery : QueryBase, ISpanFieldMaskingQuery | ||
{ | ||
protected override bool Conditionless => IsConditionless(this); | ||
public ISpanQuery Query { get; set; } | ||
public Field Field { get; set; } | ||
|
||
internal override void InternalWrapInContainer(IQueryContainer c) => c.SpanFieldMasking = this; | ||
internal static bool IsConditionless(ISpanFieldMaskingQuery q) => | ||
q.Field.IsConditionless() || q.Query == null || q.Query.Conditionless; | ||
} | ||
|
||
public class SpanFieldMaskingQueryDescriptor<T> | ||
: QueryDescriptorBase<SpanFieldMaskingQueryDescriptor<T>, ISpanFieldMaskingQuery> | ||
, ISpanFieldMaskingQuery where T : class | ||
{ | ||
protected override bool Conditionless => SpanFieldMaskingQuery.IsConditionless(this); | ||
ISpanQuery ISpanFieldMaskingQuery.Query { get; set; } | ||
Field ISpanFieldMaskingQuery.Field { get; set; } | ||
|
||
public SpanFieldMaskingQueryDescriptor<T> Field(Field field) => Assign(a => a.Field = field); | ||
|
||
public SpanFieldMaskingQueryDescriptor<T> Field(Expression<Func<T, object>> objectPath) => | ||
Assign(a => a.Field = objectPath); | ||
|
||
public SpanFieldMaskingQueryDescriptor<T> Query(Func<SpanQueryDescriptor<T>, ISpanQuery> selector) => | ||
Assign(a => a.Query = selector?.Invoke(new SpanQueryDescriptor<T>())); | ||
} | ||
} |
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
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
Oops, something went wrong.