-
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.
support predicate_token_filter elastic/elasticsearch#33431 (#3522)
* support predicate_token_filter elastic/elasticsearch#33431 * add new file * fix failing unit tests
- Loading branch information
Showing
4 changed files
with
73 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
using System; | ||
using Newtonsoft.Json; | ||
|
||
namespace Nest | ||
{ | ||
/// <summary> | ||
/// The predicate_token_filter token filter takes a predicate script, and removes tokens that do | ||
/// not match the predicate. | ||
/// </summary> | ||
public interface IPredicateTokenFilter : ITokenFilter | ||
{ | ||
/// <summary> | ||
/// a predicate script that determines whether or not the current token will | ||
/// be emitted. Note that only inline scripts are supported. | ||
/// </summary> | ||
[JsonProperty("script")] | ||
IScript Script { get; set; } | ||
} | ||
|
||
public class PredicateTokenFilter : TokenFilterBase, IPredicateTokenFilter | ||
{ | ||
public PredicateTokenFilter() : base("predicate_token_filter") { } | ||
|
||
public IScript Script { get; set; } | ||
} | ||
|
||
/// <inheritdoc cref="IPredicateTokenFilter" /> | ||
public class PredicateTokenFilterDescriptor | ||
: TokenFilterDescriptorBase<PredicateTokenFilterDescriptor, IPredicateTokenFilter>, IPredicateTokenFilter | ||
{ | ||
protected override string Type => "predicate_token_filter"; | ||
|
||
IScript IPredicateTokenFilter.Script { get; set; } | ||
|
||
/// <inheritdoc cref="IPredicateTokenFilter.Script" /> | ||
public PredicateTokenFilterDescriptor Script(Func<ScriptDescriptor, IScript> scriptSelector) => | ||
Assign(a => a.Script = scriptSelector?.Invoke(new ScriptDescriptor())); | ||
|
||
/// <inheritdoc cref="IPredicateTokenFilter.Script" /> | ||
public PredicateTokenFilterDescriptor Script(string predicate) => | ||
Assign(a => a.Script = new InlineScript(predicate)); | ||
} | ||
} |
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