11using System . IO ;
2- using FluentAssertions ;
3- using Nest . Tests . MockData . Domain ;
42using Newtonsoft . Json . Linq ;
53using NUnit . Framework ;
64using System ;
7- using System . Collections . Generic ;
8- using System . Linq ;
9- using System . Reflection ;
105using System . Text ;
11- using System . Threading . Tasks ;
126
137namespace 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