Skip to content

Commit 59446fa

Browse files
committed
Add ignore_unmapped to nested, has_parent and has_child queries
See elastic/elasticsearch#17748
1 parent 895ad57 commit 59446fa

File tree

5 files changed

+35
-8
lines changed

5 files changed

+35
-8
lines changed

src/Nest/QueryDsl/Joining/HasChild/HasChildQuery.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ public interface IHasChildQuery : IQuery
2727

2828
[JsonProperty("inner_hits")]
2929
IInnerHits InnerHits { get; set; }
30+
31+
[JsonProperty("ignore_unmapped")]
32+
bool? IgnoreUnmapped { get; set; }
3033
}
3134

3235
public class HasChildQuery : QueryBase, IHasChildQuery
@@ -42,6 +45,7 @@ public class HasChildQuery : QueryBase, IHasChildQuery
4245
public int? MaxChildren { get; set; }
4346
public QueryContainer Query { get; set; }
4447
public IInnerHits InnerHits { get; set; }
48+
public bool? IgnoreUnmapped { get; set; }
4549

4650
internal override void InternalWrapInContainer(IQueryContainer c) => c.HasChild = this;
4751
internal static bool IsConditionless(IHasChildQuery q) => q.Query == null || q.Query.IsConditionless || q.Type == null;
@@ -62,6 +66,7 @@ public class HasChildQueryDescriptor<T>
6266
int? IHasChildQuery.MaxChildren { get; set; }
6367
QueryContainer IHasChildQuery.Query { get; set; }
6468
IInnerHits IHasChildQuery.InnerHits { get; set; }
69+
bool? IHasChildQuery.IgnoreUnmapped { get; set; }
6570

6671
public HasChildQueryDescriptor()
6772
{
@@ -84,5 +89,8 @@ public HasChildQueryDescriptor<T> Query(Func<QueryContainerDescriptor<T>, QueryC
8489

8590
public HasChildQueryDescriptor<T> InnerHits(Func<InnerHitsDescriptor<T>, IInnerHits> selector = null) =>
8691
Assign(a => a.InnerHits = selector.InvokeOrDefault(new InnerHitsDescriptor<T>()));
92+
93+
public HasChildQueryDescriptor<T> IgnoreUnmapped(bool ignoreUnmapped = false) =>
94+
Assign(a => a.IgnoreUnmapped = ignoreUnmapped);
8795
}
8896
}

src/Nest/QueryDsl/Joining/HasParent/HasParentQuery.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ public interface IHasParentQuery : IQuery
2323
[JsonProperty("inner_hits")]
2424
IInnerHits InnerHits { get; set; }
2525

26+
[JsonProperty("ignore_unmapped")]
27+
bool? IgnoreUnmapped { get; set; }
2628
}
2729

2830
public class HasParentQuery : QueryBase, IHasParentQuery
@@ -37,12 +39,13 @@ public class HasParentQuery : QueryBase, IHasParentQuery
3739
public bool? Score{ get; set; }
3840
public QueryContainer Query { get; set; }
3941
public IInnerHits InnerHits { get; set; }
42+
public bool? IgnoreUnmapped { get; set; }
4043

4144
internal override void InternalWrapInContainer(IQueryContainer c) => c.HasParent = this;
4245
internal static bool IsConditionless(IHasParentQuery q) => q.Query == null || q.Query.IsConditionless || q.Type == null;
4346
}
4447

45-
public class HasParentQueryDescriptor<T>
48+
public class HasParentQueryDescriptor<T>
4649
: QueryDescriptorBase<HasParentQueryDescriptor<T>, IHasParentQuery>
4750
, IHasParentQuery where T : class
4851
{
@@ -56,6 +59,7 @@ public class HasParentQueryDescriptor<T>
5659
bool? IHasParentQuery.Score { get; set; }
5760
IInnerHits IHasParentQuery.InnerHits { get; set; }
5861
QueryContainer IHasParentQuery.Query { get; set; }
62+
bool? IHasParentQuery.IgnoreUnmapped { get; set; }
5963

6064
public HasParentQueryDescriptor() { Self.Type = TypeName.Create<T>(); }
6165

@@ -72,5 +76,8 @@ public HasParentQueryDescriptor<T> Query(Func<QueryContainerDescriptor<T>, Query
7276

7377
public HasParentQueryDescriptor<T> InnerHits(Func<InnerHitsDescriptor<T>, IInnerHits> selector = null) =>
7478
Assign(a => a.InnerHits = selector.InvokeOrDefault(new InnerHitsDescriptor<T>()));
79+
80+
public HasParentQueryDescriptor<T> IgnoreUnmapped(bool ignoreUnmapped = false) =>
81+
Assign(a => a.IgnoreUnmapped = ignoreUnmapped);
7582
}
7683
}

src/Nest/QueryDsl/Joining/Nested/NestedQuery.cs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ public interface INestedQuery : IQuery
2020
[JsonProperty("inner_hits")]
2121
IInnerHits InnerHits { get; set; }
2222

23+
[JsonProperty("ignore_unmapped")]
24+
bool? IgnoreUnmapped { get; set; }
2325
}
2426

2527
public class NestedQuery : QueryBase, INestedQuery
@@ -29,13 +31,14 @@ public class NestedQuery : QueryBase, INestedQuery
2931
public QueryContainer Query { get; set; }
3032
public Field Path { get; set; }
3133
public IInnerHits InnerHits { get; set; }
34+
public bool? IgnoreUnmapped { get; set; }
3235

3336
internal override void InternalWrapInContainer(IQueryContainer c) => c.Nested = this;
3437
internal static bool IsConditionless(INestedQuery q) => q.Path == null || q.Query.IsConditionless();
3538
}
3639

3740
[JsonObject(MemberSerialization = MemberSerialization.OptIn)]
38-
public class NestedQueryDescriptor<T>
41+
public class NestedQueryDescriptor<T>
3942
: QueryDescriptorBase<NestedQueryDescriptor<T>, INestedQuery>
4043
, INestedQuery where T : class
4144
{
@@ -44,8 +47,9 @@ public class NestedQueryDescriptor<T>
4447
QueryContainer INestedQuery.Query { get; set; }
4548
Field INestedQuery.Path { get; set; }
4649
IInnerHits INestedQuery.InnerHits { get; set; }
50+
bool? INestedQuery.IgnoreUnmapped { get; set; }
4751

48-
public NestedQueryDescriptor<T> Query(Func<QueryContainerDescriptor<T>, QueryContainer> selector) =>
52+
public NestedQueryDescriptor<T> Query(Func<QueryContainerDescriptor<T>, QueryContainer> selector) =>
4953
Assign(a => a.Query = selector?.Invoke(new QueryContainerDescriptor<T>()));
5054

5155
public NestedQueryDescriptor<T> ScoreMode(NestedScoreMode scoreMode) => Assign(a => a.ScoreMode = scoreMode);
@@ -54,7 +58,10 @@ public NestedQueryDescriptor<T> Query(Func<QueryContainerDescriptor<T>, QueryCon
5458

5559
public NestedQueryDescriptor<T> Path(Expression<Func<T, object>> objectPath) => Assign(a => a.Path = objectPath);
5660

57-
public NestedQueryDescriptor<T> InnerHits(Func<InnerHitsDescriptor<T>, IInnerHits> selector = null) =>
58-
Assign(a => a.InnerHits = selector.InvokeOrDefault(new InnerHitsDescriptor<T>()));
61+
public NestedQueryDescriptor<T> InnerHits(Func<InnerHitsDescriptor<T>, IInnerHits> selector = null) =>
62+
Assign(a => a.InnerHits = selector.InvokeOrDefault(new InnerHitsDescriptor<T>()));
63+
64+
public NestedQueryDescriptor<T> IgnoreUnmapped(bool ignoreUnmapped = false) =>
65+
Assign(a => a.IgnoreUnmapped = ignoreUnmapped);
5966
}
6067
}

src/Tests/QueryDsl/Joining/HasParent/HasParentQueryUsageTests.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ public HasParentUsageTests(ReadOnlyCluster i, EndpointUsage usage) : base(i, usa
1616
boost = 1.1,
1717
type = "developer",
1818
score = true,
19+
ignore_unmapped = true,
1920
query = new
2021
{
2122
match_all = new { }
@@ -34,7 +35,8 @@ public HasParentUsageTests(ReadOnlyCluster i, EndpointUsage usage) : base(i, usa
3435
Type = Infer.Type<Developer>(),
3536
InnerHits = new InnerHits { Explain = true },
3637
Query = new MatchAllQuery(),
37-
Score = true
38+
Score = true,
39+
IgnoreUnmapped = true
3840
};
3941

4042
protected override QueryContainer QueryFluent(QueryContainerDescriptor<Project> q) => q
@@ -44,7 +46,7 @@ protected override QueryContainer QueryFluent(QueryContainerDescriptor<Project>
4446
.InnerHits(i=>i.Explain())
4547
.Score(true)
4648
.Query(qq=>qq.MatchAll())
47-
49+
.IgnoreUnmapped(true)
4850
);
4951

5052
protected override ConditionlessWhen ConditionlessWhen => new ConditionlessWhen<IHasParentQuery>(a => a.HasParent)

src/Tests/QueryDsl/Joining/Nested/NestedQueryUsageTests.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ public NestedUsageTests(ReadOnlyCluster i, EndpointUsage usage) : base(i, usage)
3131
{ "curatedTags.name", new JArray("lorem", "ipsum") }
3232
}
3333
},
34+
ignore_unmapped = false,
3435
path = "curatedTags",
3536
inner_hits = new
3637
{
@@ -49,7 +50,8 @@ public NestedUsageTests(ReadOnlyCluster i, EndpointUsage usage) : base(i, usage)
4950
{
5051
Field = Field<Project>(p => p.CuratedTags.First().Name),
5152
Terms = new[] { "lorem", "ipsum" }
52-
}
53+
},
54+
IgnoreUnmapped = false
5355
};
5456

5557
protected override QueryContainer QueryFluent(QueryContainerDescriptor<Project> q) => q
@@ -64,6 +66,7 @@ protected override QueryContainer QueryFluent(QueryContainerDescriptor<Project>
6466
.Terms("lorem", "ipsum")
6567
)
6668
)
69+
.IgnoreUnmapped()
6770
);
6871

6972
protected override ConditionlessWhen ConditionlessWhen => new ConditionlessWhen<INestedQuery>(a => a.Nested)

0 commit comments

Comments
 (0)