Skip to content

Commit 62a0467

Browse files
committed
Deprecate Indices query
See elastic/elasticsearch#12017
1 parent 238d9f6 commit 62a0467

File tree

10 files changed

+27
-3
lines changed

10 files changed

+27
-3
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using System;
12
using Newtonsoft.Json;
23

34
namespace Nest
@@ -114,6 +115,7 @@ public interface IQueryContainer
114115
[JsonProperty("nested")]
115116
INestedQuery Nested { get; set; }
116117

118+
[Obsolete("Deprecated. You can specify _index on the query to target specific indices")]
117119
[JsonProperty("indices")]
118120
IIndicesQuery Indices { get; set; }
119121

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,10 @@ public partial class QueryContainer : IQueryContainer, IDescriptor
3737
private ISpanWithinQuery _spanWithin;
3838
private ISpanMultiTermQuery _spanMultiTerm;
3939
private INestedQuery _nested;
40+
41+
#pragma warning disable 618
4042
private IIndicesQuery _indices;
43+
#pragma warning restore 618
4144
private IFunctionScoreQuery _functionScore;
4245
private ITemplateQuery _template;
4346
private IGeoBoundingBoxQuery _geoBoundingBox;
@@ -96,7 +99,9 @@ private T Set<T>(T value) where T : IQuery
9699
ISpanWithinQuery IQueryContainer.SpanWithin { get { return _spanWithin; } set { _spanWithin = Set(value); } }
97100
ISpanMultiTermQuery IQueryContainer.SpanMultiTerm { get { return _spanMultiTerm; } set { _spanMultiTerm = Set(value); } }
98101
INestedQuery IQueryContainer.Nested { get { return _nested; } set { _nested = Set(value); } }
102+
#pragma warning disable 618
99103
IIndicesQuery IQueryContainer.Indices { get { return _indices; } set { _indices = Set(value); } }
104+
#pragma warning restore 618
100105
IFunctionScoreQuery IQueryContainer.FunctionScore { get { return _functionScore; } set { _functionScore = Set(value); } }
101106
ITemplateQuery IQueryContainer.Template { get { return _template; } set { _template = Set(value); } }
102107
IGeoBoundingBoxQuery IQueryContainer.GeoBoundingBox { get { return _geoBoundingBox; } set { _geoBoundingBox = Set(value); } }

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,8 @@ public QueryContainer Conditionless(Func<ConditionlessQueryDescriptor<T>, ICondi
129129
/// The indices query can be used when executed across multiple indices, allowing to have a query that executes
130130
/// only when executed on an index that matches a specific list of indices, and another query that executes
131131
/// when it is executed on an index that does not match the listed indices.
132-
/// </summary>
132+
/// </summary>
133+
[Obsolete("Deprecated. You can specify _index on the query to target specific indices")]
133134
public QueryContainer Indices(Func<IndicesQueryDescriptor<T>, IIndicesQuery> selector) =>
134135
WrapInContainer(selector, (query, container) => container.Indices = query);
135136

src/Nest/QueryDsl/Compound/Indices/IndicesQuery.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ namespace Nest
77
{
88
[JsonObject(MemberSerialization = MemberSerialization.OptIn)]
99
[JsonConverter(typeof(ReadAsTypeJsonConverter<IndicesQueryDescriptor<object>>))]
10+
[Obsolete("Deprecated. You can specify _index on the query to target specific indices")]
1011
public interface IIndicesQuery : IQuery
1112
{
1213
[JsonProperty("indices")]
@@ -28,6 +29,7 @@ public class NoMatchQueryContainer : QueryContainer
2829
public static implicit operator NoMatchQueryContainer(NoMatchShortcut shortcut) => new NoMatchQueryContainer { Shortcut = shortcut };
2930
}
3031

32+
[Obsolete("Deprecated. You can specify _index on the query to target specific indices")]
3133
public class IndicesQuery : QueryBase, IIndicesQuery
3234
{
3335
protected override bool Conditionless => IsConditionless(this);
@@ -40,6 +42,7 @@ internal static bool IsConditionless(IIndicesQuery q) =>
4042
q.Indices == null || q.NoMatchQuery.NotWritable() && q.Query.NotWritable();
4143
}
4244

45+
[Obsolete("Deprecated. You can specify _index on the query to target specific indices")]
4346
public class IndicesQueryDescriptor<T>
4447
: QueryDescriptorBase<IndicesQueryDescriptor<T>, IIndicesQuery>
4548
, IIndicesQuery where T : class

src/Nest/QueryDsl/Query.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ public static QueryContainer HasParent<TParent>(Func<HasParentQueryDescriptor<TP
8585
public static QueryContainer Ids(Func<IdsQueryDescriptor, IIdsQuery> selector) =>
8686
new QueryContainerDescriptor<T>().Ids(selector);
8787

88+
[Obsolete("Deprecated. You can specify _index on the query to target specific indices")]
8889
public static QueryContainer Indices(Func<IndicesQueryDescriptor<T>, IIndicesQuery> selector) =>
8990
new QueryContainerDescriptor<T>().Indices(selector);
9091

src/Nest/QueryDsl/Visitor/DslPrettyPrintVisitor.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,9 @@ private void Write(string queryType, Field field = null)
9898

9999
public virtual void Visit(IIdsQuery query) => Write("ids");
100100

101+
#pragma warning disable 618
101102
public virtual void Visit(IIndicesQuery query) => Write("indices");
103+
#pragma warning restore 618
102104

103105
public virtual void Visit(IMatchQuery query) => Write("match", query.Field);
104106

src/Nest/QueryDsl/Visitor/QueryVisitor.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,9 @@ public interface IQueryVisitor
3737
void Visit(IHasChildQuery query);
3838
void Visit(IHasParentQuery query);
3939
void Visit(IIdsQuery query);
40+
#pragma warning disable 618
4041
void Visit(IIndicesQuery query);
42+
#pragma warning restore 618
4143
void Visit(IMatchQuery query);
4244
void Visit(IMatchAllQuery query);
4345
void Visit(IMoreLikeThisQuery query);
@@ -140,7 +142,9 @@ public virtual void Visit(IHasParentQuery query) { }
140142

141143
public virtual void Visit(IIdsQuery query) { }
142144

145+
#pragma warning disable 618
143146
public virtual void Visit(IIndicesQuery query) { }
147+
#pragma warning restore 618
144148

145149
public virtual void Visit(IMatchQuery query) { }
146150

src/Nest/QueryDsl/Visitor/QueryWalker.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,12 +104,14 @@ public void Walk(IQueryContainer qd, IQueryVisitor visitor)
104104
v.Visit(d);
105105
Accept(v, d.Query);
106106
});
107+
#pragma warning disable 618
107108
VisitQuery(qd.Indices, visitor, (v, d) =>
108109
{
109110
v.Visit(d);
110111
Accept(v, d.Query);
111112
Accept(v, d.NoMatchQuery, VisitorScope.NoMatchQuery);
112113
});
114+
#pragma warning restore 618
113115
VisitQuery(qd.Nested, visitor, (v, d) =>
114116
{
115117
v.Visit(d);
@@ -166,7 +168,7 @@ public void Walk(ISpanQuery qd, IQueryVisitor visitor)
166168

167169
private static void Accept(IQueryVisitor visitor, IEnumerable<IQueryContainer> queries, VisitorScope scope = VisitorScope.Query)
168170
{
169-
if (!queries.HasAny()) return;
171+
if (queries == null) return;
170172
foreach (var f in queries) Accept(visitor, f, scope);
171173
}
172174

@@ -248,7 +250,7 @@ private static void VisitSpanSubQuery<T>(T qd, IQueryVisitor visitor, Action<IQu
248250
if (qd == null) return;
249251
VisitQuery(qd, visitor, (v, d) =>
250252
{
251-
visitor.Visit(qd as ISpanSubQuery);
253+
visitor.Visit(qd);
252254
scoped(v, d);
253255
});
254256
}

src/Tests/QueryDsl/Compound/Indices/IndicesNoMatchQueryUsageTests.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
using Tests.Framework.Integration;
33
using Tests.Framework.MockData;
44

5+
#pragma warning disable 618 // Deprecated in 5.0.0-alpha2 - see https://github.com/elastic/elasticsearch/issues/12017
6+
57
namespace Tests.QueryDsl.Compound.Indices
68
{
79
public class IndicesNoMatchQueryUsageTests : QueryDslUsageTestsBase

src/Tests/QueryDsl/Compound/Indices/IndicesQueryUsageTests.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
using Tests.Framework.MockData;
44
using static Nest.Infer;
55

6+
#pragma warning disable 618 // Deprecated in 5.0.0-alpha2 - see https://github.com/elastic/elasticsearch/issues/12017
7+
68
namespace Tests.QueryDsl.Compound.Indices
79
{
810
public class IndicesQueryUsageTests : QueryDslUsageTestsBase

0 commit comments

Comments
 (0)