Skip to content

Commit 104dcdf

Browse files
committed
Included index property for Indices Filter
index property was missing for Indices filter. It is now added. Refactored the test case
1 parent 4cf01cd commit 104dcdf

File tree

2 files changed

+29
-34
lines changed

2 files changed

+29
-34
lines changed

src/Nest/DSL/Filter/IndicesFilterDescriptor.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ public interface IIndicesFilter : IFilter
1515
[JsonProperty("indices")]
1616
IEnumerable<string> Indices { get; set; }
1717

18+
[JsonProperty("index")]
19+
string Index { get; set; }
20+
1821
[JsonProperty("filter")]
1922
[JsonConverter(typeof(CompositeJsonConverter<ReadAsTypeConverter<FilterDescriptor<object>>, CustomJsonConverter>))]
2023
IFilterContainer Filter { get; set; }
@@ -64,6 +67,7 @@ protected internal override void WrapInContainer(IFilterContainer container)
6467
public IFilterContainer Filter { get; set; }
6568
public IFilterContainer NoMatchFilter { get; set; }
6669
public IEnumerable<string> Indices { get; set; }
70+
public string Index { get; set; }
6771
}
6872

6973
public class IndicesFilterDescriptor<T> : FilterBase, IIndicesFilter where T : class
@@ -73,6 +77,7 @@ public class IndicesFilterDescriptor<T> : FilterBase, IIndicesFilter where T : c
7377
IFilterContainer IIndicesFilter.NoMatchFilter { get; set; }
7478

7579
IEnumerable<string> IIndicesFilter.Indices { get; set; }
80+
public string Index { get; set; }
7681

7782
bool IFilter.IsConditionless
7883
{

src/Tests/Nest.Tests.Unit/Reproduce/Reproduce1187Tests.cs

Lines changed: 24 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,8 @@
11
using System.IO;
2-
using FluentAssertions;
3-
using Nest.Tests.MockData.Domain;
42
using Newtonsoft.Json.Linq;
53
using NUnit.Framework;
64
using System;
7-
using System.Collections.Generic;
8-
using System.Linq;
9-
using System.Reflection;
105
using System.Text;
11-
using System.Threading.Tasks;
126

137
namespace Nest.Tests.Unit.Reproduce
148
{
@@ -18,42 +12,36 @@ public class Reproduce1187Tests : BaseJsonTests
1812
[Test]
1913
public void IsClientSideSearchQueryDeserialisable()
2014
{
21-
var newDescriptor = Deserialize<SearchDescriptor<dynamic>>(original);
15+
var newDescriptor = Deserialize<SearchDescriptor<dynamic>>(Original);
2216
var actual = Serialize(newDescriptor);//Should is empty
2317

2418
var descriptorJobject = JObject.Parse(actual);
25-
var expressionList = new object[][]
26-
{
27-
new[] {"size"},//Works
28-
new[] {"from"},//Works
29-
new[] {"query", "filtered", "query", "query_string", "fields"},//Works
30-
new[] {"query", "filtered", "filter", "bool", "must"},//Works
31-
//Can't find contents of should
32-
new object[] {"query", "filtered", "filter", "bool", "should", 0, "indices", "filter"},
33-
new object[] {"query", "filtered", "filter", "bool", "should", 0, "indices", "no_match_filter"},
34-
new[] {"aggs", "Databases", "terms", "field"},//Works
35-
new[] {"aggs", "Year", "terms", "field"}//Works
36-
};
37-
foreach (var e in expressionList)
38-
VerifyJsonPath(descriptorJobject, e);
19+
var jsonPathList = new[]
20+
{
21+
"size", "from", "query.filtered.query.query_string.fields",
22+
"query.filtered.filter.bool.must", //Works
23+
"query.filtered.filter.bool.should[0].indices.index",//Should find contents of "should"
24+
"query.filtered.filter.bool.should[0].indices.indices",
25+
"query.filtered.filter.bool.should[0].indices.filter",
26+
"query.filtered.filter.bool.should[0].indices.no_match_filter",
27+
"aggs.Databases.terms.field", //Works
28+
"aggs.Year.terms.field" //Works
29+
};
30+
foreach (var jsonPath in jsonPathList)
31+
VerifyJsonPath(descriptorJobject, jsonPath);
3932

4033
//If we do a search without the below line
4134
//it seems to contect /_all/object/_search instead of /_search
4235
newDescriptor.AllTypes().AllIndices();
4336
}
4437

45-
private static void VerifyJsonPath(JToken descriptorJobject, IEnumerable<object> strings)
46-
{
47-
foreach (var item in strings)
48-
{
49-
Assert.IsNotNull(descriptorJobject[item], item.ToString());
50-
descriptorJobject = descriptorJobject[item];
51-
if (item.ToString() == "no_match_filter")
52-
descriptorJobject.ToString().Should().Be("none");
53-
}
54-
}
38+
private static void VerifyJsonPath(JToken json, string path)
39+
{
40+
Console.WriteLine(path);
41+
Assert.IsNotNull(json.SelectToken(path));
42+
}
5543

56-
public string Serialize<T>(T obj) where T : class
44+
public string Serialize<T>(T obj) where T : class
5745
{
5846
var json = Encoding.UTF8.GetString(_client.Serializer.Serialize(obj));
5947
return json;
@@ -64,8 +52,8 @@ public T Deserialize<T>(string json) where T : class
6452
return _client.Serializer.Deserialize<T>(new MemoryStream(Encoding.UTF8.GetBytes(json)));
6553
}
6654

67-
const string original =
68-
@"{
55+
const string Original =
56+
@"{
6957
""size"":10,
7058
""from"":0,
7159
""query"":{
@@ -90,6 +78,7 @@ public T Deserialize<T>(string json) where T : class
9078
""should"":[
9179
{
9280
""indices"":{
81+
""indices"":[""index1""],
9382
""index"":""index1"",
9483
""filter"":{
9584
""terms"":{
@@ -105,6 +94,7 @@ public T Deserialize<T>(string json) where T : class
10594
},
10695
{
10796
""indices"":{
97+
""indices"":[""index2""],
10898
""index"":""index2"",
10999
""filter"":{
110100
""terms"":{

0 commit comments

Comments
 (0)