From cf0081a301884b76838d73a7795cd66f1c0f7c8f Mon Sep 17 00:00:00 2001 From: Russ Cam Date: Tue, 10 Dec 2019 11:05:30 +1000 Subject: [PATCH] Add MatchBoolPrefix query This commit adds the MatchBoolPrefix query. Closes #4247 --- .../disable-sniff-ping-per-request.asciidoc | 1 + .../connection/configuration-options.asciidoc | 2 +- .../modifying-default-connection.asciidoc | 2 + .../low-level-response-types.asciidoc | 76 ++++++++ docs/query-dsl.asciidoc | 4 + .../match-bool-prefix-usage.asciidoc | 69 +++++++ .../Abstractions/Container/IQueryContainer.cs | 3 + .../Container/QueryContainer-Assignments.cs | 7 + .../Container/QueryContainerDescriptor.cs | 4 + .../Abstractions/Query/QueryDescriptorBase.cs | 5 + .../MatchBoolPrefix/MatchBoolPrefixQuery.cs | 169 ++++++++++++++++++ src/Nest/QueryDsl/Query.cs | 4 + .../QueryDsl/Visitor/DslPrettyPrintVisitor.cs | 2 + src/Nest/QueryDsl/Visitor/QueryVisitor.cs | 4 + src/Nest/QueryDsl/Visitor/QueryWalker.cs | 1 + .../MatchBoolPrefixUsageTests.cs | 63 +++++++ 16 files changed, 415 insertions(+), 1 deletion(-) create mode 100644 docs/client-concepts/low-level/low-level-response-types.asciidoc create mode 100644 docs/query-dsl/full-text/match-bool-prefix/match-bool-prefix-usage.asciidoc create mode 100644 src/Nest/QueryDsl/FullText/MatchBoolPrefix/MatchBoolPrefixQuery.cs create mode 100644 src/Tests/Tests/QueryDsl/FullText/MatchBoolPrefix/MatchBoolPrefixUsageTests.cs diff --git a/docs/client-concepts/connection-pooling/request-overrides/disable-sniff-ping-per-request.asciidoc b/docs/client-concepts/connection-pooling/request-overrides/disable-sniff-ping-per-request.asciidoc index 23c856be59d..3892e4e2a1c 100644 --- a/docs/client-concepts/connection-pooling/request-overrides/disable-sniff-ping-per-request.asciidoc +++ b/docs/client-concepts/connection-pooling/request-overrides/disable-sniff-ping-per-request.asciidoc @@ -115,5 +115,6 @@ audit = await audit.TraceCall( ); ---- <1> disable ping and sniff + <2> no ping or sniff before the call diff --git a/docs/client-concepts/connection/configuration-options.asciidoc b/docs/client-concepts/connection/configuration-options.asciidoc index 3806aec37c9..6c05e19ffb8 100644 --- a/docs/client-concepts/connection/configuration-options.asciidoc +++ b/docs/client-concepts/connection/configuration-options.asciidoc @@ -90,7 +90,7 @@ Enables gzip compressed requests and responses. + IMPORTANT: You need to configure http compression on Elasticsearch to be able to use this + -http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/modules-http.html +https://www.elastic.co/guide/en/elasticsearch/reference/current/modules-http.html `EnableHttpPipelining`:: diff --git a/docs/client-concepts/connection/modifying-default-connection.asciidoc b/docs/client-concepts/connection/modifying-default-connection.asciidoc index c5d20540a3e..70c83d94bae 100644 --- a/docs/client-concepts/connection/modifying-default-connection.asciidoc +++ b/docs/client-concepts/connection/modifying-default-connection.asciidoc @@ -122,3 +122,5 @@ public class KerberosConnection : HttpConnection } ---- +See <> for further details. + diff --git a/docs/client-concepts/low-level/low-level-response-types.asciidoc b/docs/client-concepts/low-level/low-level-response-types.asciidoc new file mode 100644 index 00000000000..12848b89642 --- /dev/null +++ b/docs/client-concepts/low-level/low-level-response-types.asciidoc @@ -0,0 +1,76 @@ +:ref_current: https://www.elastic.co/guide/en/elasticsearch/reference/7.4 + +: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/7.x/src/Tests/Tests/ClientConcepts/LowLevel/LowLevelResponseTypes.doc.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! +//// + +[[low-level-response-types]] +=== Low Level Client Response Types + +[source,csharp] +---- +return @"{ +""boolean"" : true, +""string"" : ""v"", +""number"" : 29, +""array"" : [1, 2, 3, 4], +""object"" : { + ""first"" : ""value1"", + ""second"" : ""value2"", + ""nested"" : { ""x"" : ""value3"" } +}, +""array_of_objects"" : [ + { + ""first"" : ""value11"", + ""second"" : ""value12"", + ""nested"" : { ""x"" : ""value4"" } + }, + { + ""first"" : ""value21"", + ""second"" : ""value22"", + ""nested"" : { ""x"" : ""value5"" }, + ""complex.nested"" : { ""x"" : ""value6"" } + } +] + }"; +---- + +[float] +=== DynamicResponse + +[source,csharp] +---- +var response = Client.LowLevel.Search(PostData.Empty); + +response.Get("object.first").Should() + .NotBeEmpty() + .And.Be("value1"); + +response.Get("object._arbitrary_key_").Should() + .NotBeEmpty() + .And.Be("first"); + +response.Get("array.1").Should().Be(2); +response.Get("array.1").Should().Be(2); +response.Get("number").Should().Be(29); +response.Get("number").Should().Be(29); +response.Get("number_does_not_exist").Should().Be(null); +response.Get("number").Should().Be(29); + +response.Get("array_of_objects.1.second").Should() + .NotBeEmpty() + .And.Be("value22"); + +response.Get("array_of_objects.1.complex\\.nested.x").Should() + .NotBeEmpty() + .And.Be("value6"); +---- + diff --git a/docs/query-dsl.asciidoc b/docs/query-dsl.asciidoc index 648f058e1a4..cb77994271c 100644 --- a/docs/query-dsl.asciidoc +++ b/docs/query-dsl.asciidoc @@ -51,6 +51,8 @@ NEST exposes all of the full text queries available in Elasticsearch * <> +* <> + * <> * <> @@ -71,6 +73,8 @@ include::query-dsl/full-text/intervals/intervals-usage.asciidoc[] include::query-dsl/full-text/match/match-usage.asciidoc[] +include::query-dsl/full-text/match-bool-prefix/match-bool-prefix-usage.asciidoc[] + include::query-dsl/full-text/match-phrase/match-phrase-usage.asciidoc[] include::query-dsl/full-text/match-phrase-prefix/match-phrase-prefix-usage.asciidoc[] diff --git a/docs/query-dsl/full-text/match-bool-prefix/match-bool-prefix-usage.asciidoc b/docs/query-dsl/full-text/match-bool-prefix/match-bool-prefix-usage.asciidoc new file mode 100644 index 00000000000..d183b2dfac7 --- /dev/null +++ b/docs/query-dsl/full-text/match-bool-prefix/match-bool-prefix-usage.asciidoc @@ -0,0 +1,69 @@ +:ref_current: https://www.elastic.co/guide/en/elasticsearch/reference/7.4 + +: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/7.x/src/Tests/Tests/QueryDsl/FullText/MatchBoolPrefix/MatchBoolPrefixUsageTests.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! +//// + +[[match-bool-prefix-usage]] +=== Match Bool Prefix Usage + +==== Fluent DSL example + +[source,csharp] +---- +q +.MatchBoolPrefix(c => c + .Field(p => p.Description) + .Analyzer("standard") + .Boost(1.1) + .Query("lorem ips") + .Fuzziness(Fuzziness.AutoLength(3, 6)) + .FuzzyTranspositions() + .FuzzyRewrite(MultiTermQueryRewrite.TopTermsBlendedFreqs(10)) + .Name("named_query") +) +---- + +==== Object Initializer syntax example + +[source,csharp] +---- +new MatchBoolPrefixQuery +{ + Field = Field(p => p.Description), + Analyzer = "standard", + Boost = 1.1, + Name = "named_query", + Query = "lorem ips", + Fuzziness = Fuzziness.AutoLength(3, 6), + FuzzyTranspositions = true, + FuzzyRewrite = MultiTermQueryRewrite.TopTermsBlendedFreqs(10), +} +---- + +[source,javascript] +.Example json output +---- +{ + "match_bool_prefix": { + "description": { + "_name": "named_query", + "boost": 1.1, + "query": "lorem ips", + "analyzer": "standard", + "fuzzy_rewrite": "top_terms_blended_freqs_10", + "fuzziness": "AUTO:3,6", + "fuzzy_transpositions": true + } + } +} +---- + diff --git a/src/Nest/QueryDsl/Abstractions/Container/IQueryContainer.cs b/src/Nest/QueryDsl/Abstractions/Container/IQueryContainer.cs index ac01a38d4d8..4ed6ecc1b2b 100644 --- a/src/Nest/QueryDsl/Abstractions/Container/IQueryContainer.cs +++ b/src/Nest/QueryDsl/Abstractions/Container/IQueryContainer.cs @@ -78,6 +78,9 @@ public interface IQueryContainer [DataMember(Name ="match_all")] IMatchAllQuery MatchAll { get; set; } + [DataMember(Name ="match_bool_prefix")] + IMatchBoolPrefixQuery MatchBoolPrefix { get; set; } + [DataMember(Name ="match_none")] IMatchNoneQuery MatchNone { get; set; } diff --git a/src/Nest/QueryDsl/Abstractions/Container/QueryContainer-Assignments.cs b/src/Nest/QueryDsl/Abstractions/Container/QueryContainer-Assignments.cs index ef84c6f5d96..e4a02f3d2c1 100644 --- a/src/Nest/QueryDsl/Abstractions/Container/QueryContainer-Assignments.cs +++ b/src/Nest/QueryDsl/Abstractions/Container/QueryContainer-Assignments.cs @@ -28,6 +28,7 @@ public partial class QueryContainer : IQueryContainer, IDescriptor private IIntervalsQuery _intervals; private IMatchQuery _match; private IMatchAllQuery _matchAllQuery; + private IMatchBoolPrefixQuery _matchBoolPrefixQuery; private IMatchNoneQuery _matchNoneQuery; private IMatchPhraseQuery _matchPhrase; private IMatchPhrasePrefixQuery _matchPhrasePrefix; @@ -189,6 +190,12 @@ IMatchAllQuery IQueryContainer.MatchAll set => _matchAllQuery = Set(value); } + IMatchBoolPrefixQuery IQueryContainer.MatchBoolPrefix + { + get => _matchBoolPrefixQuery; + set => _matchBoolPrefixQuery = Set(value); + } + IMatchNoneQuery IQueryContainer.MatchNone { get => _matchNoneQuery; diff --git a/src/Nest/QueryDsl/Abstractions/Container/QueryContainerDescriptor.cs b/src/Nest/QueryDsl/Abstractions/Container/QueryContainerDescriptor.cs index 42daf74004c..c98e0413ba2 100644 --- a/src/Nest/QueryDsl/Abstractions/Container/QueryContainerDescriptor.cs +++ b/src/Nest/QueryDsl/Abstractions/Container/QueryContainerDescriptor.cs @@ -97,6 +97,10 @@ public QueryContainer Match(Func, IMatchQuery> selector) public QueryContainer MatchPhrase(Func, IMatchPhraseQuery> selector) => WrapInContainer(selector, (query, container) => container.MatchPhrase = query); + /// + public QueryContainer MatchBoolPrefix(Func, IMatchBoolPrefixQuery> selector) => + WrapInContainer(selector, (query, container) => container.MatchBoolPrefix = query); + /// /// The match_phrase_prefix is the same as match_phrase, expect it allows for prefix matches on the last term /// in the text diff --git a/src/Nest/QueryDsl/Abstractions/Query/QueryDescriptorBase.cs b/src/Nest/QueryDsl/Abstractions/Query/QueryDescriptorBase.cs index 1a65db3f066..ec05fc7b0b5 100644 --- a/src/Nest/QueryDsl/Abstractions/Query/QueryDescriptorBase.cs +++ b/src/Nest/QueryDsl/Abstractions/Query/QueryDescriptorBase.cs @@ -5,6 +5,7 @@ public abstract class QueryDescriptorBase where TDescriptor : QueryDescriptorBase, TInterface where TInterface : class, IQuery { + /// protected abstract bool Conditionless { get; } double? IQuery.Boost { get; set; } @@ -18,12 +19,16 @@ public abstract class QueryDescriptorBase bool IQuery.IsWritable => Self.IsVerbatim || !Self.Conditionless; string IQuery.Name { get; set; } + /// public TDescriptor Name(string name) => Assign(name, (a, v) => a.Name = v); + /// public TDescriptor Boost(double? boost) => Assign(boost, (a, v) => a.Boost = v); + /// public TDescriptor Verbatim(bool verbatim = true) => Assign(verbatim, (a, v) => a.IsVerbatim = v); + /// public TDescriptor Strict(bool strict = true) => Assign(strict, (a, v) => a.IsStrict = v); } } diff --git a/src/Nest/QueryDsl/FullText/MatchBoolPrefix/MatchBoolPrefixQuery.cs b/src/Nest/QueryDsl/FullText/MatchBoolPrefix/MatchBoolPrefixQuery.cs new file mode 100644 index 00000000000..fd21ffc7572 --- /dev/null +++ b/src/Nest/QueryDsl/FullText/MatchBoolPrefix/MatchBoolPrefixQuery.cs @@ -0,0 +1,169 @@ +using System.Runtime.Serialization; +using Elasticsearch.Net.Utf8Json; + +namespace Nest +{ + /// + /// A match_bool_prefix query analyzes its input and constructs a bool query from the terms. + /// Each term except the last is used in a term query. The last term is used in a prefix query. + /// + /// + /// Supported in Elasticsearch 7.2.0+ + /// + [InterfaceDataContract] + [JsonFormatter(typeof(FieldNameQueryFormatter))] + public interface IMatchBoolPrefixQuery : IFieldNameQuery + { + /// + /// The analyzer to use for the query + /// + [DataMember(Name = "analyzer")] + string Analyzer { get; set; } + + /// + /// Allows fuzzy matching based on the type of field being queried. + /// Applies only to the term sub queries constructed, and not the prefix query for the final term. + /// + [DataMember(Name = "fuzziness")] + IFuzziness Fuzziness { get; set; } + + /// + /// Controls how the query is rewritten if is set. + /// In this scenario, the default is . + /// Applies only to the term sub queries constructed, and not the prefix query for the final term. + /// + [DataMember(Name = "fuzzy_rewrite")] + MultiTermQueryRewrite FuzzyRewrite { get; set; } + + /// + /// Sets whether transpositions are supported in fuzzy queries. + /// + /// The default metric used by fuzzy queries to determine a match is the Damerau-Levenshtein + /// distance formula which supports transpositions. Setting transposition to false will + /// switch to classic Levenshtein distance. + /// If not set, Damerau-Levenshtein distance metric will be used. + /// Applies only to the term sub queries constructed, and not the prefix query for the final term. + /// + [DataMember(Name = "fuzzy_transpositions")] + bool? FuzzyTranspositions { get; set; } + + /// + /// Controls the number of terms fuzzy queries will expand to. Defaults to 50. + /// Applies only to the term sub queries constructed, and not the prefix query for the final term. + /// + [DataMember(Name = "max_expansions")] + int? MaxExpansions { get; set; } + + /// + /// A value controlling how many "should" clauses in the resulting boolean query should match. + /// It can be an absolute value, a percentage or a combination of both. + /// Applies to the bool query constructed. + /// + [DataMember(Name = "minimum_should_match")] + MinimumShouldMatch MinimumShouldMatch { get; set; } + + /// + /// The operator used if no explicit operator is specified. + /// The default operator is . + /// Applies to the bool query constructed. + /// + [DataMember(Name = "operator")] + Operator? Operator { get; set; } + + /// + /// Set the prefix length for fuzzy queries. Default is 0. + /// Applies only to the term sub queries constructed, and not the prefix query for the final term. + /// + [DataMember(Name = "prefix_length")] + int? PrefixLength { get; set; } + + /// + /// The query + /// + [DataMember(Name = "query")] + string Query { get; set; } + } + + /// + public class MatchBoolPrefixQuery : FieldNameQueryBase, IMatchBoolPrefixQuery + { + /// + public string Analyzer { get; set; } + + /// + public IFuzziness Fuzziness { get; set; } + + /// + public MultiTermQueryRewrite FuzzyRewrite { get; set; } + + /// + public bool? FuzzyTranspositions { get; set; } + + /// + public int? MaxExpansions { get; set; } + + /// + public MinimumShouldMatch MinimumShouldMatch { get; set; } + + /// + public Operator? Operator { get; set; } + + /// + public int? PrefixLength { get; set; } + + /// + public string Query { get; set; } + + protected override bool Conditionless => IsConditionless(this); + + internal override void InternalWrapInContainer(IQueryContainer c) => c.MatchBoolPrefix = this; + + internal static bool IsConditionless(IMatchBoolPrefixQuery q) => q.Field.IsConditionless() || q.Query.IsNullOrEmpty(); + } + + /// + public class MatchBoolPrefixQueryDescriptor + : FieldNameQueryDescriptorBase, IMatchBoolPrefixQuery, T>, IMatchBoolPrefixQuery + where T : class + { + protected override bool Conditionless => MatchBoolPrefixQuery.IsConditionless(this); + string IMatchBoolPrefixQuery.Analyzer { get; set; } + IFuzziness IMatchBoolPrefixQuery.Fuzziness { get; set; } + MultiTermQueryRewrite IMatchBoolPrefixQuery.FuzzyRewrite { get; set; } + bool? IMatchBoolPrefixQuery.FuzzyTranspositions { get; set; } + int? IMatchBoolPrefixQuery.MaxExpansions { get; set; } + MinimumShouldMatch IMatchBoolPrefixQuery.MinimumShouldMatch { get; set; } + Operator? IMatchBoolPrefixQuery.Operator { get; set; } + int? IMatchBoolPrefixQuery.PrefixLength { get; set; } + string IMatchBoolPrefixQuery.Query { get; set; } + + /// + public MatchBoolPrefixQueryDescriptor Analyzer(string analyzer) => Assign(analyzer, (a, v) => a.Analyzer = v); + + /// + public MatchBoolPrefixQueryDescriptor Fuzziness(Fuzziness fuzziness) => Assign(fuzziness, (a, v) => a.Fuzziness = v); + + /// + public MatchBoolPrefixQueryDescriptor FuzzyTranspositions(bool? fuzzyTranspositions = true) => + Assign(fuzzyTranspositions, (a, v) => a.FuzzyTranspositions = v); + + /// + public MatchBoolPrefixQueryDescriptor FuzzyRewrite(MultiTermQueryRewrite rewrite) => Assign(rewrite, (a, v) => a.FuzzyRewrite = v); + + /// + public MatchBoolPrefixQueryDescriptor MaxExpansions(int? maxExpansions) => Assign(maxExpansions, (a, v) => a.MaxExpansions = v); + + /// + public MatchBoolPrefixQueryDescriptor MinimumShouldMatch(MinimumShouldMatch minimumShouldMatch) => + Assign(minimumShouldMatch, (a, v) => a.MinimumShouldMatch = v); + + /// + public MatchBoolPrefixQueryDescriptor Operator(Operator? op) => Assign(op, (a, v) => a.Operator = v); + + /// + public MatchBoolPrefixQueryDescriptor PrefixLength(int? prefixLength) => Assign(prefixLength, (a, v) => a.PrefixLength = v); + + /// + public MatchBoolPrefixQueryDescriptor Query(string query) => Assign(query, (a, v) => a.Query = v); + } +} diff --git a/src/Nest/QueryDsl/Query.cs b/src/Nest/QueryDsl/Query.cs index 5704a977ae5..7b859c3a52f 100644 --- a/src/Nest/QueryDsl/Query.cs +++ b/src/Nest/QueryDsl/Query.cs @@ -74,6 +74,10 @@ public static QueryContainer Match(Func, IMatchQuery> se public static QueryContainer MatchAll(Func selector = null) => new QueryContainerDescriptor().MatchAll(selector); + /// + public static QueryContainer MatchBoolPrefix(Func, IMatchBoolPrefixQuery> selector = null) => + new QueryContainerDescriptor().MatchBoolPrefix(selector); + public static QueryContainer MatchNone(Func selector = null) => new QueryContainerDescriptor().MatchNone(selector); diff --git a/src/Nest/QueryDsl/Visitor/DslPrettyPrintVisitor.cs b/src/Nest/QueryDsl/Visitor/DslPrettyPrintVisitor.cs index 6e5b6c55562..769ead05a3f 100644 --- a/src/Nest/QueryDsl/Visitor/DslPrettyPrintVisitor.cs +++ b/src/Nest/QueryDsl/Visitor/DslPrettyPrintVisitor.cs @@ -149,6 +149,8 @@ private void WriteShape(IGeoShape shape, IFieldLookup indexedField, Field field, public virtual void Visit(IMatchAllQuery query) => Write("match_all"); + public virtual void Visit(IMatchBoolPrefixQuery query) => Write("match_bool_prefix"); + public virtual void Visit(IMatchNoneQuery query) => Write("match_none"); public virtual void Visit(IMoreLikeThisQuery query) => Write("more_like_this"); diff --git a/src/Nest/QueryDsl/Visitor/QueryVisitor.cs b/src/Nest/QueryDsl/Visitor/QueryVisitor.cs index 2a719ffc33a..f833aa0d5dc 100644 --- a/src/Nest/QueryDsl/Visitor/QueryVisitor.cs +++ b/src/Nest/QueryDsl/Visitor/QueryVisitor.cs @@ -64,6 +64,8 @@ public interface IQueryVisitor void Visit(IMatchAllQuery query); + void Visit(IMatchBoolPrefixQuery query); + void Visit(IMatchNoneQuery query); void Visit(IMoreLikeThisQuery query); @@ -213,6 +215,8 @@ public virtual void Visit(IMatchPhrasePrefixQuery query) { } public virtual void Visit(IMatchAllQuery query) { } + public virtual void Visit(IMatchBoolPrefixQuery query) { } + public virtual void Visit(IMatchNoneQuery query) { } public virtual void Visit(IMoreLikeThisQuery query) { } diff --git a/src/Nest/QueryDsl/Visitor/QueryWalker.cs b/src/Nest/QueryDsl/Visitor/QueryWalker.cs index 35c99a94677..322642347a6 100644 --- a/src/Nest/QueryDsl/Visitor/QueryWalker.cs +++ b/src/Nest/QueryDsl/Visitor/QueryWalker.cs @@ -44,6 +44,7 @@ public void Walk(IQueryContainer qd, IQueryVisitor visitor) VisitQuery(qd.Wildcard, visitor, (v, d) => v.Visit(d)); VisitQuery(qd.Match, visitor, (v, d) => v.Visit(d)); VisitQuery(qd.MatchPhrase, visitor, (v, d) => v.Visit(d)); + VisitQuery(qd.MatchBoolPrefix, visitor, (v, d) => v.Visit(d)); VisitQuery(qd.MatchPhrasePrefix, visitor, (v, d) => v.Visit(d)); VisitQuery(qd.Script, visitor, (v, d) => v.Visit(d)); VisitQuery(qd.ScriptScore, visitor, (v, d) => v.Visit(d)); diff --git a/src/Tests/Tests/QueryDsl/FullText/MatchBoolPrefix/MatchBoolPrefixUsageTests.cs b/src/Tests/Tests/QueryDsl/FullText/MatchBoolPrefix/MatchBoolPrefixUsageTests.cs new file mode 100644 index 00000000000..76f6a6117da --- /dev/null +++ b/src/Tests/Tests/QueryDsl/FullText/MatchBoolPrefix/MatchBoolPrefixUsageTests.cs @@ -0,0 +1,63 @@ +using Elastic.Xunit.XunitPlumbing; +using Nest; +using Tests.Core.ManagedElasticsearch.Clusters; +using Tests.Domain; +using Tests.Framework.EndpointTests.TestState; +using static Nest.Infer; + +namespace Tests.QueryDsl.FullText.MatchBoolPrefix +{ + [SkipVersion("<7.2.0", "added in 7.2.0")] + public class MatchBoolPrefixUsageTests : QueryDslUsageTestsBase + { + public MatchBoolPrefixUsageTests(ReadOnlyCluster i, EndpointUsage usage) : base(i, usage) { } + + protected override ConditionlessWhen ConditionlessWhen => new ConditionlessWhen(a => a.MatchBoolPrefix) + { + q => q.Query = null, + q => q.Query = string.Empty, + q => q.Field = null + }; + + protected override QueryContainer QueryInitializer => new MatchBoolPrefixQuery + { + Field = Field(p => p.Description), + Analyzer = "standard", + Boost = 1.1, + Name = "named_query", + Query = "lorem ips", + Fuzziness = Fuzziness.AutoLength(3, 6), + FuzzyTranspositions = true, + FuzzyRewrite = MultiTermQueryRewrite.TopTermsBlendedFreqs(10), + }; + + protected override object QueryJson => new + { + match_bool_prefix = new + { + description = new + { + _name = "named_query", + boost = 1.1, + query = "lorem ips", + analyzer = "standard", + fuzzy_rewrite = "top_terms_blended_freqs_10", + fuzziness = "AUTO:3,6", + fuzzy_transpositions = true, + } + } + }; + + protected override QueryContainer QueryFluent(QueryContainerDescriptor q) => q + .MatchBoolPrefix(c => c + .Field(p => p.Description) + .Analyzer("standard") + .Boost(1.1) + .Query("lorem ips") + .Fuzziness(Fuzziness.AutoLength(3, 6)) + .FuzzyTranspositions() + .FuzzyRewrite(MultiTermQueryRewrite.TopTermsBlendedFreqs(10)) + .Name("named_query") + ); + } +}