reaching max depth on json with simple searches.

Vote:
 

Hi all, i'm troubleshooting an scenario that happens only when I'm looking for straight numbers (treated always as strings).

Looks like my searh elements are getting nested somehow and when try to have the json query, I'm getting EPiServer.Find.MaxSerializationDepthExceededException

The following query is being created as per the next code.

            var searchResultList =  searchRequests.Select(x => new Tuple<SearchRequestBody, Action<SearchCommand>>(x.Item1.RequestBody, x.Item1.CommandAction));

            List<SearchResults<JObject>> list = multiSearch.Client.MultiSearch<JObject>(searchResultList, null).ToList<SearchResults<JObject>>();

here is the big nested json as result, the one who raises the expection above. 

It only happens with certain numeric codes, not with non existen words or numbers or anything else.

   "size":5,
   "query":{
      "filtered":{
         "query":{
            "filtered":{
               "query":{
                  "function_score":{
                     "query":{
                        "custom_filters_score":{
                           "query":{
                              "filtered":{
                                 "query":{
                                    "bool":{
                                       "should":[
                                          {
                                             "bool":{
                                                "should":[
                                                   {
                                                      "bool":{
                                                         "should":[
                                                            {
                                                               "bool":{
                                                                  "should":[
                                                                     {
                                                                        "bool":{
                                                                           "should":[
                                                                              {
                                                                                 "query_string":{
                                                                                    "fields":[
                                                                                       "_all"
                                                                                    ],
                                                                                    "query":701200522,
                                                                                    "analyzer":"synonym"
                                                                                 }
                                                                              },
                                                                              {
                                                                                 "constant_score":{
                                                                                    "filter":{
                                                                                       "or":[
                                                                                          {
                                                                                             "ids":null
                                                                                          }
                                                                                       ]
                                                                                    }
                                                                                 }
                                                                              }
                                                                           ]
                                                                        }
                                                                     }
                                                                  ]
                                                               }
                                                            }
                                                         ]
                                                      }
                                                   }
                                                ]
                                             }
                                          }
                                       ]
                                    }
                                 }
                              }
                           }
                        }
                     }
                  }
               }
            }
         }
      }
   }
}
#265381
Oct 21, 2021 6:47
Vote:
 

Andrew (Optimizely)

Nov 5, 2021, 10:18 AM EDT

Hello,
 
From reviewing it looks like nested bools are the source of this issue. The code responsible for these bools is not within GetAccoMultiSearchResult(). Bools are generated when creating a MultiFieldQueryStringQuery which is done if you use For(). Wildcard implementations generally also make use of BoolQuery.
 
There are implementations out there that don't rewrite the existing BoolQuery but rather spawn nested BoolQueries within the already existing BoolQuery. From what has been discussed the creation of the bools is unintentional and there is no really need to nest them. The right way is to rewrite the existing and merely add Should clauses.
 
If you could provide the full search code I could see if we could get some further clarification on how the search code might be optimized.

Thank you,

Andrew
Support Team

ticket related https://support.optimizely.com/hc/en-us/requests/793647

#266286
Nov 05, 2021 20:26
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.