November Happy Hour will be moved to Thursday December 5th.

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
Vote:
 

Hi,

I have the same issue but using Search and not MultiSearch query. Here is the code:

var query = _client.Search<WebProductCard>()
                .For(q).WithAndAsDefaultOperator()
                .InField(d => d.DisplayName, _startPage?.FindSearchRelevance?.DisplayNameRelevance ?? 0)
                .AndInField(d => d.Brand, _startPage?.FindSearchRelevance?.BrandRelevance ?? 0)
                .AndInField(d => d.ItemNumbers, _startPage?.FindSearchRelevance?.ItemNumbersRelevance ?? 0)
                .AndInField(d => d.SubCategory, _startPage?.FindSearchRelevance?.SubcategoryRelevance ?? 0)
                .AndInField(d => d.ColorNames, _startPage?.FindSearchRelevance?.ColorRelevance ?? 0)
                .AndInField(d => d.Description, _startPage?.FindSearchRelevance?.DescriptionRelevance ?? 0)
                .AndInField(d => d.AttributeGroup, _startPage?.FindSearchRelevance?.AttributeGroupRelevance ?? 0)
                .UsingPersonalization()
                .UsingSynonyms()
                .ApplyBestBets()
                .Track()
                .BoostMatching(x => x.InStock.Match(true), _startPage?.FindSearchBoost?.StockBoost ?? 0)
                .BoostMatching(x => x.SpecialOffer.Match("true"), _startPage?.FindSearchBoost?.PromotionBoost ?? 0)
                .BoostMatching(x => x.HasSample.Match(true), _startPage?.FindSearchBoost?.SampleBoost ?? 0)
                .BoostMatchingBoostList(boostedProducts)
                .FilterLangauge()
                .Include(d => d.DisplayName.AnyWordBeginsWith(q))
                .Include(d => d.Brand.AnyWordBeginsWith(q))
                .FuzzyFilter(d => d.DisplayName, q)
                .FuzzyFilter(d => d.Brand, q)
                .FilterOnCurrentSite()
                .Select(x => new WebProductProjectionModel
                {

                        Code = x.Code,
                        DisplayName = !string.IsNullOrEmpty(x.DisplayName.AsHighlighted()) ? x.DisplayName.AsHighlighted(new HighlightSpec
                        {
                            PreTag = "<b>",
                            PostTag = "</b>",
                            NumberOfFragments = 1,
                            FragmentSize = 200,
                        }) : x.DisplayName,
                        ContentLink = x.ContentLink,
                        ListPrice = x.NowPrice,
                        Url = x.Url,
                        Image = x.ImageUrl,
                        IsBuyableFromList = !x.HasVariants
                    }).Take(5);

                var result = query.StaticallyCacheFor(_cacheTime).GetResult();
                return result.Hits;

It is throwing an error sometimes and I don't have a clue on what's the trigger. Here is the nested json below.

{
	"size": 5,
	"query": {
		"filtered": {
			"query": {
				"filtered": {
					"query": {
						"bool": {
							"should": [
								{
									"bool": {
										"should": [
											{
												"bool": {
													"should": [
														{
															"bool": {
																"should": [
																	{
																		"filtered": {
																			"query": {
																				"custom_filters_score": {
																					"query": {
																						"function_score": {
																							"query": {
																								"bool": {
																									"should": [
																										{
																											"query_string": {
																												"fields": [
																													"DisplayName$$string.standard^100",
																													"Brand$$string.standard^10",
																													"ItemNumbers.standard^5",
																													"SubCategory$$string.standard^5",
																													"ColorNames$$string.standard^5",
																													"Description$$string.standard^1",
																													"AttributeGroup$$string.standard^10"
																												],
																												"query": "Carpet",
																												"analyzer": "standard",
																												"default_operator": "AND"
																											}
																										},
																										{
																											"constant_score": {
																												"filter": {
																													"or": [
																														{
																															"ids": null
																														}
																													]
																												}
																											}
																										}
																									]
																								}
																							}
																						}
																					}
																				}
																			}
																		}
																	}
																]
															}
														}
													]
												}
											}
										]
									}
								}
							]
						}
					}
				}
			}
		}
	}
}
#284433
Jul 26, 2022 10:06
dada - Aug 30, 2022 8:27
Hi Christopher,

Could you share the code for BoostMatchingBoostList and FuzzyFilter?
* 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.