Skip to content

Commit 9fab17e

Browse files
authored
Add MatchBoolPrefix query (#4256)
This commit adds the MatchBoolPrefix query. Closes #4247
1 parent 7d282a9 commit 9fab17e

File tree

16 files changed

+415
-1
lines changed

16 files changed

+415
-1
lines changed

docs/client-concepts/connection-pooling/request-overrides/disable-sniff-ping-per-request.asciidoc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,5 +115,6 @@ audit = await audit.TraceCall(
115115
);
116116
----
117117
<1> disable ping and sniff
118+
118119
<2> no ping or sniff before the call
119120

docs/client-concepts/connection/configuration-options.asciidoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ Enables gzip compressed requests and responses.
9090
+
9191
IMPORTANT: You need to configure http compression on Elasticsearch to be able to use this
9292
+
93-
http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/modules-http.html
93+
https://www.elastic.co/guide/en/elasticsearch/reference/current/modules-http.html
9494

9595
`EnableHttpPipelining`::
9696

docs/client-concepts/connection/modifying-default-connection.asciidoc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,3 +122,5 @@ public class KerberosConnection : HttpConnection
122122
}
123123
----
124124

125+
See <<working-with-certificates, Working with certificates>> for further details.
126+
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
:ref_current: https://www.elastic.co/guide/en/elasticsearch/reference/7.4
2+
3+
:github: https://github.com/elastic/elasticsearch-net
4+
5+
:nuget: https://www.nuget.org/packages
6+
7+
////
8+
IMPORTANT NOTE
9+
==============
10+
This file has been generated from https://github.com/elastic/elasticsearch-net/tree/7.x/src/Tests/Tests/ClientConcepts/LowLevel/LowLevelResponseTypes.doc.cs.
11+
If you wish to submit a PR for any spelling mistakes, typos or grammatical errors for this file,
12+
please modify the original csharp file found at the link and submit the PR with that change. Thanks!
13+
////
14+
15+
[[low-level-response-types]]
16+
=== Low Level Client Response Types
17+
18+
[source,csharp]
19+
----
20+
return @"{
21+
""boolean"" : true,
22+
""string"" : ""v"",
23+
""number"" : 29,
24+
""array"" : [1, 2, 3, 4],
25+
""object"" : {
26+
""first"" : ""value1"",
27+
""second"" : ""value2"",
28+
""nested"" : { ""x"" : ""value3"" }
29+
},
30+
""array_of_objects"" : [
31+
{
32+
""first"" : ""value11"",
33+
""second"" : ""value12"",
34+
""nested"" : { ""x"" : ""value4"" }
35+
},
36+
{
37+
""first"" : ""value21"",
38+
""second"" : ""value22"",
39+
""nested"" : { ""x"" : ""value5"" },
40+
""complex.nested"" : { ""x"" : ""value6"" }
41+
}
42+
]
43+
}";
44+
----
45+
46+
[float]
47+
=== DynamicResponse
48+
49+
[source,csharp]
50+
----
51+
var response = Client.LowLevel.Search<DynamicResponse>(PostData.Empty);
52+
53+
response.Get<string>("object.first").Should()
54+
.NotBeEmpty()
55+
.And.Be("value1");
56+
57+
response.Get<string>("object._arbitrary_key_").Should()
58+
.NotBeEmpty()
59+
.And.Be("first");
60+
61+
response.Get<int>("array.1").Should().Be(2);
62+
response.Get<long>("array.1").Should().Be(2);
63+
response.Get<long>("number").Should().Be(29);
64+
response.Get<long?>("number").Should().Be(29);
65+
response.Get<long?>("number_does_not_exist").Should().Be(null);
66+
response.Get<long?>("number").Should().Be(29);
67+
68+
response.Get<string>("array_of_objects.1.second").Should()
69+
.NotBeEmpty()
70+
.And.Be("value22");
71+
72+
response.Get<string>("array_of_objects.1.complex\\.nested.x").Should()
73+
.NotBeEmpty()
74+
.And.Be("value6");
75+
----
76+

docs/query-dsl.asciidoc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ NEST exposes all of the full text queries available in Elasticsearch
5151

5252
* <<match-usage,Match Usage>>
5353

54+
* <<match-bool-prefix-usage,Match Bool Prefix Usage>>
55+
5456
* <<match-phrase-usage,Match Phrase Usage>>
5557

5658
* <<match-phrase-prefix-usage,Match Phrase Prefix Usage>>
@@ -71,6 +73,8 @@ include::query-dsl/full-text/intervals/intervals-usage.asciidoc[]
7173

7274
include::query-dsl/full-text/match/match-usage.asciidoc[]
7375

76+
include::query-dsl/full-text/match-bool-prefix/match-bool-prefix-usage.asciidoc[]
77+
7478
include::query-dsl/full-text/match-phrase/match-phrase-usage.asciidoc[]
7579

7680
include::query-dsl/full-text/match-phrase-prefix/match-phrase-prefix-usage.asciidoc[]
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
:ref_current: https://www.elastic.co/guide/en/elasticsearch/reference/7.4
2+
3+
:github: https://github.com/elastic/elasticsearch-net
4+
5+
:nuget: https://www.nuget.org/packages
6+
7+
////
8+
IMPORTANT NOTE
9+
==============
10+
This file has been generated from https://github.com/elastic/elasticsearch-net/tree/7.x/src/Tests/Tests/QueryDsl/FullText/MatchBoolPrefix/MatchBoolPrefixUsageTests.cs.
11+
If you wish to submit a PR for any spelling mistakes, typos or grammatical errors for this file,
12+
please modify the original csharp file found at the link and submit the PR with that change. Thanks!
13+
////
14+
15+
[[match-bool-prefix-usage]]
16+
=== Match Bool Prefix Usage
17+
18+
==== Fluent DSL example
19+
20+
[source,csharp]
21+
----
22+
q
23+
.MatchBoolPrefix(c => c
24+
.Field(p => p.Description)
25+
.Analyzer("standard")
26+
.Boost(1.1)
27+
.Query("lorem ips")
28+
.Fuzziness(Fuzziness.AutoLength(3, 6))
29+
.FuzzyTranspositions()
30+
.FuzzyRewrite(MultiTermQueryRewrite.TopTermsBlendedFreqs(10))
31+
.Name("named_query")
32+
)
33+
----
34+
35+
==== Object Initializer syntax example
36+
37+
[source,csharp]
38+
----
39+
new MatchBoolPrefixQuery
40+
{
41+
Field = Field<Project>(p => p.Description),
42+
Analyzer = "standard",
43+
Boost = 1.1,
44+
Name = "named_query",
45+
Query = "lorem ips",
46+
Fuzziness = Fuzziness.AutoLength(3, 6),
47+
FuzzyTranspositions = true,
48+
FuzzyRewrite = MultiTermQueryRewrite.TopTermsBlendedFreqs(10),
49+
}
50+
----
51+
52+
[source,javascript]
53+
.Example json output
54+
----
55+
{
56+
"match_bool_prefix": {
57+
"description": {
58+
"_name": "named_query",
59+
"boost": 1.1,
60+
"query": "lorem ips",
61+
"analyzer": "standard",
62+
"fuzzy_rewrite": "top_terms_blended_freqs_10",
63+
"fuzziness": "AUTO:3,6",
64+
"fuzzy_transpositions": true
65+
}
66+
}
67+
}
68+
----
69+

src/Nest/QueryDsl/Abstractions/Container/IQueryContainer.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,9 @@ public interface IQueryContainer
7878
[DataMember(Name ="match_all")]
7979
IMatchAllQuery MatchAll { get; set; }
8080

81+
[DataMember(Name ="match_bool_prefix")]
82+
IMatchBoolPrefixQuery MatchBoolPrefix { get; set; }
83+
8184
[DataMember(Name ="match_none")]
8285
IMatchNoneQuery MatchNone { get; set; }
8386

src/Nest/QueryDsl/Abstractions/Container/QueryContainer-Assignments.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ public partial class QueryContainer : IQueryContainer, IDescriptor
2828
private IIntervalsQuery _intervals;
2929
private IMatchQuery _match;
3030
private IMatchAllQuery _matchAllQuery;
31+
private IMatchBoolPrefixQuery _matchBoolPrefixQuery;
3132
private IMatchNoneQuery _matchNoneQuery;
3233
private IMatchPhraseQuery _matchPhrase;
3334
private IMatchPhrasePrefixQuery _matchPhrasePrefix;
@@ -189,6 +190,12 @@ IMatchAllQuery IQueryContainer.MatchAll
189190
set => _matchAllQuery = Set(value);
190191
}
191192

193+
IMatchBoolPrefixQuery IQueryContainer.MatchBoolPrefix
194+
{
195+
get => _matchBoolPrefixQuery;
196+
set => _matchBoolPrefixQuery = Set(value);
197+
}
198+
192199
IMatchNoneQuery IQueryContainer.MatchNone
193200
{
194201
get => _matchNoneQuery;

src/Nest/QueryDsl/Abstractions/Container/QueryContainerDescriptor.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,10 @@ public QueryContainer Match(Func<MatchQueryDescriptor<T>, IMatchQuery> selector)
9797
public QueryContainer MatchPhrase(Func<MatchPhraseQueryDescriptor<T>, IMatchPhraseQuery> selector) =>
9898
WrapInContainer(selector, (query, container) => container.MatchPhrase = query);
9999

100+
/// <inheritdoc cref="IMatchBoolPrefixQuery"/>
101+
public QueryContainer MatchBoolPrefix(Func<MatchBoolPrefixQueryDescriptor<T>, IMatchBoolPrefixQuery> selector) =>
102+
WrapInContainer(selector, (query, container) => container.MatchBoolPrefix = query);
103+
100104
/// <summary>
101105
/// The match_phrase_prefix is the same as match_phrase, expect it allows for prefix matches on the last term
102106
/// in the text

src/Nest/QueryDsl/Abstractions/Query/QueryDescriptorBase.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ public abstract class QueryDescriptorBase<TDescriptor, TInterface>
55
where TDescriptor : QueryDescriptorBase<TDescriptor, TInterface>, TInterface
66
where TInterface : class, IQuery
77
{
8+
/// <inheritdoc cref="IQuery.Conditionless"/>
89
protected abstract bool Conditionless { get; }
910

1011
double? IQuery.Boost { get; set; }
@@ -18,12 +19,16 @@ public abstract class QueryDescriptorBase<TDescriptor, TInterface>
1819
bool IQuery.IsWritable => Self.IsVerbatim || !Self.Conditionless;
1920
string IQuery.Name { get; set; }
2021

22+
/// <inheritdoc cref="IQuery.Name"/>
2123
public TDescriptor Name(string name) => Assign(name, (a, v) => a.Name = v);
2224

25+
/// <inheritdoc cref="IQuery.Boost"/>
2326
public TDescriptor Boost(double? boost) => Assign(boost, (a, v) => a.Boost = v);
2427

28+
/// <inheritdoc cref="IQuery.IsVerbatim"/>
2529
public TDescriptor Verbatim(bool verbatim = true) => Assign(verbatim, (a, v) => a.IsVerbatim = v);
2630

31+
/// <inheritdoc cref="IQuery.IsStrict"/>
2732
public TDescriptor Strict(bool strict = true) => Assign(strict, (a, v) => a.IsStrict = v);
2833
}
2934
}

0 commit comments

Comments
 (0)