Skip to content

[Backport 8.1] Add range query #6518

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
Jul 12, 2022
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
@@ -0,0 +1,12 @@
// 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 Elastic.Transport.Products.Elasticsearch;

namespace Elastic.Clients.Elasticsearch;

public static class ElasticsearchResponseBaseExtensions
{
public static bool IsSuccess(this ElasticsearchResponseBase response) => response.ApiCall is not null && response.ApiCall.Success;
}
Original file line number Diff line number Diff line change
Expand Up @@ -500,6 +500,55 @@ public override void Write(Utf8JsonWriter writer, Operator value, JsonSerializer
}
}

[JsonConverter(typeof(RangeRelationConverter))]
public enum RangeRelation
{
[EnumMember(Value = "within")]
Within,
[EnumMember(Value = "intersects")]
Intersects,
[EnumMember(Value = "contains")]
Contains
}

internal sealed class RangeRelationConverter : JsonConverter<RangeRelation>
{
public override RangeRelation Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{
var enumString = reader.GetString();
switch (enumString)
{
case "within":
return RangeRelation.Within;
case "intersects":
return RangeRelation.Intersects;
case "contains":
return RangeRelation.Contains;
}

ThrowHelper.ThrowJsonException();
return default;
}

public override void Write(Utf8JsonWriter writer, RangeRelation value, JsonSerializerOptions options)
{
switch (value)
{
case RangeRelation.Within:
writer.WriteStringValue("within");
return;
case RangeRelation.Intersects:
writer.WriteStringValue("intersects");
return;
case RangeRelation.Contains:
writer.WriteStringValue("contains");
return;
}

writer.WriteNullValue();
}
}

[JsonConverter(typeof(SimpleQueryStringFlagConverter))]
public enum SimpleQueryStringFlag
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,5 @@ public partial class MigrationFeature
[JsonInclude]
[JsonPropertyName("feature_name")]
public string FeatureName { get; init; }

[JsonInclude]
[JsonPropertyName("indices")]
public IReadOnlyCollection<Elastic.Clients.Elasticsearch.Migration.MigrationFeatureIndexInfo> Indices { get; init; }

[JsonInclude]
[JsonPropertyName("migration_status")]
public Elastic.Clients.Elasticsearch.Migration.MigrationStatus MigrationStatus { get; init; }

[JsonInclude]
[JsonPropertyName("minimum_index_version")]
public string MinimumIndexVersion { get; init; }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,229 @@
// 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.
//
// ███╗ ██╗ ██████╗ ████████╗██╗ ██████╗███████╗
// ████╗ ██║██╔═══██╗╚══██╔══╝██║██╔════╝██╔════╝
// ██╔██╗ ██║██║ ██║ ██║ ██║██║ █████╗
// ██║╚██╗██║██║ ██║ ██║ ██║██║ ██╔══╝
// ██║ ╚████║╚██████╔╝ ██║ ██║╚██████╗███████╗
// ╚═╝ ╚═══╝ ╚═════╝ ╚═╝ ╚═╝ ╚═════╝╚══════╝
// ------------------------------------------------
//
// This file is automatically generated.
// Please do not edit these files manually.
//
// ------------------------------------------------

using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Text.Json;
using System.Text.Json.Serialization;

#nullable restore
namespace Elastic.Clients.Elasticsearch.QueryDsl
{
public partial class DateRangeQuery : RangeQueryBase
{
[JsonInclude]
[JsonPropertyName("format")]
public string? Format { get; set; }

[JsonInclude]
[JsonPropertyName("from")]
public string? From { get; set; }

[JsonInclude]
[JsonPropertyName("gt")]
public string? Gt { get; set; }

[JsonInclude]
[JsonPropertyName("gte")]
public string? Gte { get; set; }

[JsonInclude]
[JsonPropertyName("lt")]
public string? Lt { get; set; }

[JsonInclude]
[JsonPropertyName("lte")]
public string? Lte { get; set; }

[JsonInclude]
[JsonPropertyName("time_zone")]
public string? TimeZone { get; set; }

[JsonInclude]
[JsonPropertyName("to")]
public string? To { get; set; }
}

public sealed partial class DateRangeQueryDescriptor : SerializableDescriptorBase<DateRangeQueryDescriptor>
{
internal DateRangeQueryDescriptor(Action<DateRangeQueryDescriptor> configure) => configure.Invoke(this);
public DateRangeQueryDescriptor() : base()
{
}

private string? QueryNameValue { get; set; }

private float? BoostValue { get; set; }

private string? FormatValue { get; set; }

private string? FromValue { get; set; }

private string? GtValue { get; set; }

private string? GteValue { get; set; }

private string? LtValue { get; set; }

private string? LteValue { get; set; }

private Elastic.Clients.Elasticsearch.QueryDsl.RangeRelation? RelationValue { get; set; }

private string? TimeZoneValue { get; set; }

private string? ToValue { get; set; }

public DateRangeQueryDescriptor QueryName(string? queryName)
{
QueryNameValue = queryName;
return Self;
}

public DateRangeQueryDescriptor Boost(float? boost)
{
BoostValue = boost;
return Self;
}

public DateRangeQueryDescriptor Format(string? format)
{
FormatValue = format;
return Self;
}

public DateRangeQueryDescriptor From(string? from)
{
FromValue = from;
return Self;
}

public DateRangeQueryDescriptor Gt(string? gt)
{
GtValue = gt;
return Self;
}

public DateRangeQueryDescriptor Gte(string? gte)
{
GteValue = gte;
return Self;
}

public DateRangeQueryDescriptor Lt(string? lt)
{
LtValue = lt;
return Self;
}

public DateRangeQueryDescriptor Lte(string? lte)
{
LteValue = lte;
return Self;
}

public DateRangeQueryDescriptor Relation(Elastic.Clients.Elasticsearch.QueryDsl.RangeRelation? relation)
{
RelationValue = relation;
return Self;
}

public DateRangeQueryDescriptor TimeZone(string? timeZone)
{
TimeZoneValue = timeZone;
return Self;
}

public DateRangeQueryDescriptor To(string? to)
{
ToValue = to;
return Self;
}

protected override void Serialize(Utf8JsonWriter writer, JsonSerializerOptions options, IElasticsearchClientSettings settings)
{
writer.WriteStartObject();
if (!string.IsNullOrEmpty(QueryNameValue))
{
writer.WritePropertyName("_name");
writer.WriteStringValue(QueryNameValue);
}

if (BoostValue.HasValue)
{
writer.WritePropertyName("boost");
writer.WriteNumberValue(BoostValue.Value);
}

if (FormatValue is not null)
{
writer.WritePropertyName("format");
JsonSerializer.Serialize(writer, FormatValue, options);
}

if (FromValue is not null)
{
writer.WritePropertyName("from");
JsonSerializer.Serialize(writer, FromValue, options);
}

if (GtValue is not null)
{
writer.WritePropertyName("gt");
JsonSerializer.Serialize(writer, GtValue, options);
}

if (GteValue is not null)
{
writer.WritePropertyName("gte");
JsonSerializer.Serialize(writer, GteValue, options);
}

if (LtValue is not null)
{
writer.WritePropertyName("lt");
JsonSerializer.Serialize(writer, LtValue, options);
}

if (LteValue is not null)
{
writer.WritePropertyName("lte");
JsonSerializer.Serialize(writer, LteValue, options);
}

if (RelationValue is not null)
{
writer.WritePropertyName("relation");
JsonSerializer.Serialize(writer, RelationValue, options);
}

if (TimeZoneValue is not null)
{
writer.WritePropertyName("time_zone");
JsonSerializer.Serialize(writer, TimeZoneValue, options);
}

if (ToValue is not null)
{
writer.WritePropertyName("to");
JsonSerializer.Serialize(writer, ToValue, options);
}

writer.WriteEndObject();
}
}
}
Loading