-
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.
[Backport master] Support mapping runtime fields (#5234)
* Support mapping runtime fields * Add missing XML comment for PIT * Fixes for master namespaces Co-authored-by: Steve Gordon <sgordon@hotmail.co.uk>
- Loading branch information
1 parent
6894e47
commit f0b2e5d
Showing
8 changed files
with
359 additions
and
0 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
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,59 @@ | ||
// Licensed to Elasticsearch B.V under one or more agreements. | ||
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License. | ||
// See the LICENSE file in the project root for more information | ||
|
||
using System.Runtime.Serialization; | ||
using Nest.Utf8Json; | ||
|
||
namespace Nest | ||
{ | ||
[InterfaceDataContract] | ||
[ReadAs(typeof(RuntimeField))] | ||
public interface IRuntimeField | ||
{ | ||
/// <summary> | ||
/// Runtime fields with a type of date can accept the format parameter exactly as the date field type. | ||
/// <see cref="DateFormat" /> | ||
/// </summary> | ||
[DataMember(Name = "format")] | ||
string Format { get; set; } | ||
|
||
/// <summary> | ||
/// The script to be evaluated for field calculation at search time. | ||
/// </summary> | ||
[DataMember(Name = "script")] | ||
IStoredScript Script { get; set; } | ||
|
||
/// <summary> | ||
/// The datatype of the runtime field. | ||
/// </summary> | ||
[DataMember(Name = "type")] | ||
FieldType Type { get; set; } | ||
} | ||
|
||
public class RuntimeField : IRuntimeField | ||
{ | ||
/// <inheritdoc /> | ||
public string Format { get; set; } | ||
/// <inheritdoc /> | ||
public IStoredScript Script { get; set; } | ||
/// <inheritdoc /> | ||
public FieldType Type { get; set; } | ||
} | ||
|
||
public class RuntimeFieldDescriptor | ||
: DescriptorBase<RuntimeFieldDescriptor, IRuntimeField>, IRuntimeField | ||
{ | ||
public RuntimeFieldDescriptor(FieldType fieldType) => Self.Type = fieldType; | ||
|
||
string IRuntimeField.Format { get; set; } | ||
IStoredScript IRuntimeField.Script { get; set; } | ||
FieldType IRuntimeField.Type { get; set; } | ||
|
||
public RuntimeFieldDescriptor Format(string format) => Assign(format, (a, v) => a.Format = v); | ||
|
||
public RuntimeFieldDescriptor Script(IStoredScript script) => Assign(script, (a, v) => a.Script = v); | ||
|
||
public RuntimeFieldDescriptor Script(string source) => Assign(source, (a, v) => a.Script = new PainlessScript(source)); | ||
} | ||
} |
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,36 @@ | ||
// Licensed to Elasticsearch B.V under one or more agreements. | ||
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License. | ||
// See the LICENSE file in the project root for more information | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using Nest.Utf8Json; | ||
|
||
namespace Nest | ||
{ | ||
[JsonFormatter(typeof(VerbatimDictionaryKeysFormatter<RuntimeFields, IRuntimeFields, string, IRuntimeField>))] | ||
public interface IRuntimeFields : IIsADictionary<string, IRuntimeField> { } | ||
|
||
public class RuntimeFields : IsADictionaryBase<string, IRuntimeField>, IRuntimeFields | ||
{ | ||
public RuntimeFields() { } | ||
|
||
public RuntimeFields(IDictionary<string, IRuntimeField> container) : base(container) { } | ||
|
||
public RuntimeFields(Dictionary<string, IRuntimeField> container) : base(container) { } | ||
|
||
public void Add(string name, IRuntimeField runtimeField) => BackingDictionary.Add(name, runtimeField); | ||
} | ||
|
||
public class RuntimeFieldsDescriptor | ||
: IsADictionaryDescriptorBase<RuntimeFieldsDescriptor, RuntimeFields, string, IRuntimeField> | ||
{ | ||
public RuntimeFieldsDescriptor() : base(new RuntimeFields()) { } | ||
|
||
public RuntimeFieldsDescriptor RuntimeField(string name, FieldType type, Func<RuntimeFieldDescriptor, IRuntimeField> selector) => | ||
Assign(name, selector?.Invoke(new RuntimeFieldDescriptor(type))); | ||
|
||
public RuntimeFieldsDescriptor RuntimeField(string name, FieldType type) => | ||
Assign(name, new RuntimeFieldDescriptor(type)); | ||
} | ||
} |
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.