diff --git a/src/Nest/QueryDsl/Joining/HasChild/HasChildQuery.cs b/src/Nest/QueryDsl/Joining/HasChild/HasChildQuery.cs index 239064efa94..ddebe9f20e2 100644 --- a/src/Nest/QueryDsl/Joining/HasChild/HasChildQuery.cs +++ b/src/Nest/QueryDsl/Joining/HasChild/HasChildQuery.cs @@ -27,6 +27,9 @@ public interface IHasChildQuery : IQuery [JsonProperty("inner_hits")] IInnerHits InnerHits { get; set; } + + [JsonProperty("ignore_unmapped")] + bool? IgnoreUnmapped { get; set; } } public class HasChildQuery : QueryBase, IHasChildQuery @@ -42,6 +45,7 @@ public class HasChildQuery : QueryBase, IHasChildQuery public int? MaxChildren { get; set; } public QueryContainer Query { get; set; } public IInnerHits InnerHits { get; set; } + public bool? IgnoreUnmapped { get; set; } internal override void InternalWrapInContainer(IQueryContainer c) => c.HasChild = this; internal static bool IsConditionless(IHasChildQuery q) => q.Query == null || q.Query.IsConditionless || q.Type == null; @@ -62,6 +66,7 @@ public class HasChildQueryDescriptor int? IHasChildQuery.MaxChildren { get; set; } QueryContainer IHasChildQuery.Query { get; set; } IInnerHits IHasChildQuery.InnerHits { get; set; } + bool? IHasChildQuery.IgnoreUnmapped { get; set; } public HasChildQueryDescriptor() { @@ -84,5 +89,8 @@ public HasChildQueryDescriptor Query(Func, QueryC public HasChildQueryDescriptor InnerHits(Func, IInnerHits> selector = null) => Assign(a => a.InnerHits = selector.InvokeOrDefault(new InnerHitsDescriptor())); + + public HasChildQueryDescriptor IgnoreUnmapped(bool ignoreUnmapped = false) => + Assign(a => a.IgnoreUnmapped = ignoreUnmapped); } } diff --git a/src/Nest/QueryDsl/Joining/HasParent/HasParentQuery.cs b/src/Nest/QueryDsl/Joining/HasParent/HasParentQuery.cs index e5ebbfcce5d..661e83c260e 100644 --- a/src/Nest/QueryDsl/Joining/HasParent/HasParentQuery.cs +++ b/src/Nest/QueryDsl/Joining/HasParent/HasParentQuery.cs @@ -23,6 +23,8 @@ public interface IHasParentQuery : IQuery [JsonProperty("inner_hits")] IInnerHits InnerHits { get; set; } + [JsonProperty("ignore_unmapped")] + bool? IgnoreUnmapped { get; set; } } public class HasParentQuery : QueryBase, IHasParentQuery @@ -37,12 +39,13 @@ public class HasParentQuery : QueryBase, IHasParentQuery public bool? Score{ get; set; } public QueryContainer Query { get; set; } public IInnerHits InnerHits { get; set; } + public bool? IgnoreUnmapped { get; set; } internal override void InternalWrapInContainer(IQueryContainer c) => c.HasParent = this; internal static bool IsConditionless(IHasParentQuery q) => q.Query == null || q.Query.IsConditionless || q.Type == null; } - public class HasParentQueryDescriptor + public class HasParentQueryDescriptor : QueryDescriptorBase, IHasParentQuery> , IHasParentQuery where T : class { @@ -56,6 +59,7 @@ public class HasParentQueryDescriptor bool? IHasParentQuery.Score { get; set; } IInnerHits IHasParentQuery.InnerHits { get; set; } QueryContainer IHasParentQuery.Query { get; set; } + bool? IHasParentQuery.IgnoreUnmapped { get; set; } public HasParentQueryDescriptor() { Self.Type = TypeName.Create(); } @@ -72,5 +76,8 @@ public HasParentQueryDescriptor Query(Func, Query public HasParentQueryDescriptor InnerHits(Func, IInnerHits> selector = null) => Assign(a => a.InnerHits = selector.InvokeOrDefault(new InnerHitsDescriptor())); + + public HasParentQueryDescriptor IgnoreUnmapped(bool ignoreUnmapped = false) => + Assign(a => a.IgnoreUnmapped = ignoreUnmapped); } } diff --git a/src/Nest/QueryDsl/Joining/Nested/NestedQuery.cs b/src/Nest/QueryDsl/Joining/Nested/NestedQuery.cs index ae32cf7c55b..eee49ae2ac7 100644 --- a/src/Nest/QueryDsl/Joining/Nested/NestedQuery.cs +++ b/src/Nest/QueryDsl/Joining/Nested/NestedQuery.cs @@ -20,6 +20,8 @@ public interface INestedQuery : IQuery [JsonProperty("inner_hits")] IInnerHits InnerHits { get; set; } + [JsonProperty("ignore_unmapped")] + bool? IgnoreUnmapped { get; set; } } public class NestedQuery : QueryBase, INestedQuery @@ -29,13 +31,14 @@ public class NestedQuery : QueryBase, INestedQuery public QueryContainer Query { get; set; } public Field Path { get; set; } public IInnerHits InnerHits { get; set; } + public bool? IgnoreUnmapped { get; set; } internal override void InternalWrapInContainer(IQueryContainer c) => c.Nested = this; internal static bool IsConditionless(INestedQuery q) => q.Path == null || q.Query.IsConditionless(); } [JsonObject(MemberSerialization = MemberSerialization.OptIn)] - public class NestedQueryDescriptor + public class NestedQueryDescriptor : QueryDescriptorBase, INestedQuery> , INestedQuery where T : class { @@ -44,8 +47,9 @@ public class NestedQueryDescriptor QueryContainer INestedQuery.Query { get; set; } Field INestedQuery.Path { get; set; } IInnerHits INestedQuery.InnerHits { get; set; } + bool? INestedQuery.IgnoreUnmapped { get; set; } - public NestedQueryDescriptor Query(Func, QueryContainer> selector) => + public NestedQueryDescriptor Query(Func, QueryContainer> selector) => Assign(a => a.Query = selector?.Invoke(new QueryContainerDescriptor())); public NestedQueryDescriptor ScoreMode(NestedScoreMode scoreMode) => Assign(a => a.ScoreMode = scoreMode); @@ -54,7 +58,10 @@ public NestedQueryDescriptor Query(Func, QueryCon public NestedQueryDescriptor Path(Expression> objectPath) => Assign(a => a.Path = objectPath); - public NestedQueryDescriptor InnerHits(Func, IInnerHits> selector = null) => - Assign(a => a.InnerHits = selector.InvokeOrDefault(new InnerHitsDescriptor())); + public NestedQueryDescriptor InnerHits(Func, IInnerHits> selector = null) => + Assign(a => a.InnerHits = selector.InvokeOrDefault(new InnerHitsDescriptor())); + + public NestedQueryDescriptor IgnoreUnmapped(bool ignoreUnmapped = false) => + Assign(a => a.IgnoreUnmapped = ignoreUnmapped); } } diff --git a/src/Tests/QueryDsl/Joining/HasParent/HasParentQueryUsageTests.cs b/src/Tests/QueryDsl/Joining/HasParent/HasParentQueryUsageTests.cs index 4301cdf2d54..cfd3e32fd67 100644 --- a/src/Tests/QueryDsl/Joining/HasParent/HasParentQueryUsageTests.cs +++ b/src/Tests/QueryDsl/Joining/HasParent/HasParentQueryUsageTests.cs @@ -16,6 +16,7 @@ public HasParentUsageTests(ReadOnlyCluster i, EndpointUsage usage) : base(i, usa boost = 1.1, type = "developer", score = true, + ignore_unmapped = true, query = new { match_all = new { } @@ -34,7 +35,8 @@ public HasParentUsageTests(ReadOnlyCluster i, EndpointUsage usage) : base(i, usa Type = Infer.Type(), InnerHits = new InnerHits { Explain = true }, Query = new MatchAllQuery(), - Score = true + Score = true, + IgnoreUnmapped = true }; protected override QueryContainer QueryFluent(QueryContainerDescriptor q) => q @@ -44,7 +46,7 @@ protected override QueryContainer QueryFluent(QueryContainerDescriptor .InnerHits(i=>i.Explain()) .Score(true) .Query(qq=>qq.MatchAll()) - + .IgnoreUnmapped(true) ); protected override ConditionlessWhen ConditionlessWhen => new ConditionlessWhen(a => a.HasParent) diff --git a/src/Tests/QueryDsl/Joining/Nested/NestedQueryUsageTests.cs b/src/Tests/QueryDsl/Joining/Nested/NestedQueryUsageTests.cs index 8ede5525dda..460dac8ca00 100644 --- a/src/Tests/QueryDsl/Joining/Nested/NestedQueryUsageTests.cs +++ b/src/Tests/QueryDsl/Joining/Nested/NestedQueryUsageTests.cs @@ -31,6 +31,7 @@ public NestedUsageTests(ReadOnlyCluster i, EndpointUsage usage) : base(i, usage) { "curatedTags.name", new JArray("lorem", "ipsum") } } }, + ignore_unmapped = false, path = "curatedTags", inner_hits = new { @@ -49,7 +50,8 @@ public NestedUsageTests(ReadOnlyCluster i, EndpointUsage usage) : base(i, usage) { Field = Field(p => p.CuratedTags.First().Name), Terms = new[] { "lorem", "ipsum" } - } + }, + IgnoreUnmapped = false }; protected override QueryContainer QueryFluent(QueryContainerDescriptor q) => q @@ -64,6 +66,7 @@ protected override QueryContainer QueryFluent(QueryContainerDescriptor .Terms("lorem", "ipsum") ) ) + .IgnoreUnmapped() ); protected override ConditionlessWhen ConditionlessWhen => new ConditionlessWhen(a => a.Nested)