Skip to content

Add MatchBoolPrefix query #4256

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 11, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -115,5 +115,6 @@ audit = await audit.TraceCall(
);
----
<1> disable ping and sniff

<2> no ping or sniff before the call

Original file line number Diff line number Diff line change
Expand Up @@ -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`::

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,3 +122,5 @@ public class KerberosConnection : HttpConnection
}
----

See <<working-with-certificates, Working with certificates>> for further details.

76 changes: 76 additions & 0 deletions docs/client-concepts/low-level/low-level-response-types.asciidoc
Original file line number Diff line number Diff line change
@@ -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<DynamicResponse>(PostData.Empty);

response.Get<string>("object.first").Should()
.NotBeEmpty()
.And.Be("value1");

response.Get<string>("object._arbitrary_key_").Should()
.NotBeEmpty()
.And.Be("first");

response.Get<int>("array.1").Should().Be(2);
response.Get<long>("array.1").Should().Be(2);
response.Get<long>("number").Should().Be(29);
response.Get<long?>("number").Should().Be(29);
response.Get<long?>("number_does_not_exist").Should().Be(null);
response.Get<long?>("number").Should().Be(29);

response.Get<string>("array_of_objects.1.second").Should()
.NotBeEmpty()
.And.Be("value22");

response.Get<string>("array_of_objects.1.complex\\.nested.x").Should()
.NotBeEmpty()
.And.Be("value6");
----

4 changes: 4 additions & 0 deletions docs/query-dsl.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ NEST exposes all of the full text queries available in Elasticsearch

* <<match-usage,Match Usage>>

* <<match-bool-prefix-usage,Match Bool Prefix Usage>>

* <<match-phrase-usage,Match Phrase Usage>>

* <<match-phrase-prefix-usage,Match Phrase Prefix Usage>>
Expand All @@ -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[]
Expand Down
Original file line number Diff line number Diff line change
@@ -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<Project>(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
}
}
}
----

3 changes: 3 additions & 0 deletions src/Nest/QueryDsl/Abstractions/Container/IQueryContainer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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; }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,10 @@ public QueryContainer Match(Func<MatchQueryDescriptor<T>, IMatchQuery> selector)
public QueryContainer MatchPhrase(Func<MatchPhraseQueryDescriptor<T>, IMatchPhraseQuery> selector) =>
WrapInContainer(selector, (query, container) => container.MatchPhrase = query);

/// <inheritdoc cref="IMatchBoolPrefixQuery"/>
public QueryContainer MatchBoolPrefix(Func<MatchBoolPrefixQueryDescriptor<T>, IMatchBoolPrefixQuery> selector) =>
WrapInContainer(selector, (query, container) => container.MatchBoolPrefix = query);

/// <summary>
/// The match_phrase_prefix is the same as match_phrase, expect it allows for prefix matches on the last term
/// in the text
Expand Down
5 changes: 5 additions & 0 deletions src/Nest/QueryDsl/Abstractions/Query/QueryDescriptorBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ public abstract class QueryDescriptorBase<TDescriptor, TInterface>
where TDescriptor : QueryDescriptorBase<TDescriptor, TInterface>, TInterface
where TInterface : class, IQuery
{
/// <inheritdoc cref="IQuery.Conditionless"/>
protected abstract bool Conditionless { get; }

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

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

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

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

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