Запрос искажен, ошибка пустого предложения в ElasticSearch - PullRequest
0 голосов
/ 03 мая 2018

Я получаю ошибку ниже в нашем .net-коде, а также в Kibana при обновлении до 6.xasticsearch. Хотя до того, как предупреждение о градации обновлений регистрировалось, но оно возвращало результаты, основанные на запросе. Теперь никаких результатов не возвращается.

Ниже мой упругий запрос:

     {
        "from": 0,
    "size": 50,
      "query": {
     "bool": {
       "must": [
       {
          "bool": {
           "must": [
              {},
              {},
              {}, 
              {},
              {}
                  ]
                }
             }
        ],
     "filter": [
         {
          "bool": {
            "must": [
             {
            "range": {
              "image_id": {
                "gte": 0
              }
            }
          },
          {
            "term": {
              "collection.name.raw": {
                "value": "Hollis, ME: Tax List of Hollis, Maine, 1862"
              }
            }
          }
        ]
         }
         }
          ]
          }
       },
       "aggs": {
        "Category": {
            "terms": {
               "field": "collection.category.name.raw",
                 "size": 1000
                     }
                   }
                 }
                }

Ниже приведена ошибка:

 {
   "error": {
      "root_cause": [
     {
         "type": "illegal_argument_exception",
       "reason": "query malformed, empty clause found at [94:16]"
     }
                  ],
      "type": "illegal_argument_exception",
      "reason": "query malformed, empty clause found at [94:16]"
     },
    "status": 400
     }

Пустые предложения генерируются в сценариях, когда пользователь не вводил никаких данных. Я проверил ссылки ниже, но не нашел ничего, чтобы решить мою проблему. Link1

Link2 LINK3

         sr.Query = Query<Model.Name>
                .Bool(fd => fd
                    .Must(iq => iq
                    .Bool(b => b
                        .Must(must => must

                        #region Attributes
                            //TODO: Update for nested attribute object
                                .Raw(attributesQuery)
                        #endregion

                    #region ExactLocation
     , must => must.DisMax(d => d
                                .Queries(qs => qs
                                    .Bool(ib => ib
                                        .Should(should => should
                                                .Raw(locationrawExactMatch)

       ).MinimumShouldMatch(numRawLocations)
                                    )
                                        , qs => qs.Bool(ib => ib
                                        .Must(mu => mu
                                                .Raw(locationExactAllTerms)
                                                , mu => mu.Bool(bo => bo
                                                .Should(should => should

       .Raw(locationExactDuplicates)

           ).MinimumShouldMatch(numLocations)
                                            )
                                        )
                                    )
                                )
                            )
                    #endregion

                    #region Location
           , must => must.Bool(boo => boo
                                    .Should(sh => sh
                                        .DisMax(d => d
                                            .Queries(qs => qs
                                                    .Raw(locationMultiMatch)
                                                , qs => qs.Bool(ib => ib
                                                    .Must(mu => mu

                           .Raw(locationExactMatch)
                                                    )
                                                )
                                                , qs => qs.Bool(ib => ib
                                                    .Must(should => should
                                                        .Match(m => m

                 .Field("location.city.name")

            //.Type(TextQueryType.boolean)

           .Operator(Operator.Or)

           .Query((locationCityStateCountry[0] + " " + 
             locationCityStateCountry[1]).Replace(",", "").Trim())

               .Analyzer("standard")
                                                        )
                                                        , should => 
                 should.MatchPhrasePrefix(m => m

                .Field("location.region.name")
                                                            .Query(CultureInfo.CurrentCulture.TextInfo.ToTitleCase(locationCityStateCountry[1].ToLower().Trim()))
                                                            .Analyzer("standard")
                                                        )
                                                    ).Boost(8.0)
                                                    .Should(should => should
                                                            .MatchPhrase(m => m
                                                            .Field("location.city.name")
                                                               // .Fuzziness(Fuzziness.EditDistance(0)) //cant set 0.1!
                                                            .Query((locationCityStateCountry[0] + " " + locationCityStateCountry[1]).Replace(",", "").Trim())
                                                            .Analyzer("standard")
                                                        )
                                                        , should => should.MatchPhrase(m => m
                                                            .Field("location.city.name")
                                                               // .Fuzziness(Fuzziness.EditDistance(0)) //cant set 0.1!
                                                            .Query(locationCityStateCountry[0].Replace(",", "").Trim())
                                                            .Analyzer("standard")
                                                        )
                                                        , should => should.MatchPhrasePrefix(m => m
                                                            .Field("location.region.name")
                                                            .Query(CultureInfo.CurrentCulture.TextInfo.ToTitleCase(locationCityStateCountry[1].ToLower().Trim()))
                                                            .Analyzer("standard")
                                                        )
                                                        , should => should.Match(m => m
                                                            .Field("location.county.name")
                                                                .Operator(Operator.Or)
                                                                .Fuzziness(Fuzziness.EditDistance(0)) //cant set 0.1!
                                                            .Query((locationCityStateCountry[1] + " " + locationCityStateCountry[2]).Replace(",", "").Trim())
                                                            .Analyzer("standard")
                                                        )
                                                        , should => should.Match(m => m
                                                            .Field("location.country.name")
                                                                .Operator(Operator.Or)
                                                                .Fuzziness(Fuzziness.EditDistance(0)) //cant set 0.1!
                                                                .Query((locationCityStateCountry[1] + " " + locationCityStateCountry[2] + locationCityStateCountry[3]).Replace(",", "").Trim())
                                                            .Analyzer("standard")
                                                        )
                                                        ).MinimumShouldMatch(Math.Max(locations.Length, 2))
                                                    .Boost(4.0)
                                                )
                                            )
                                        )
                                       , sh => sh.DisMax(di => di
                                            .Queries(qi => qi
                                                .Bool(ib => ib
                                                    .Should(should => should
                                                            .Raw(locationExactMatch)
                                                        ).MinimumShouldMatch(numLocations)
                                                )
                                                 , qi => qi.Bool(ib => ib
                                                    .Must(mu => mu
                                                            .Raw(locationExactAll)
                                                        , mu => mu.Bool(bo => bo
                                                            .Should(should => should
                                                                    .Raw(locationExactDupes)
                                                                ).MinimumShouldMatch(numLocations)
                                                        )
                                                    )
                                                )
                                            )
                                        )
                                    )
                                )

                    #endregion

                    #region Primary Name
             , must => must.MatchPhrase(m => m
                                .Field("last_name")
                                .Query(lastNameSoundex)
                                .Analyzer("my_analyzer")
                                   // .Fuzziness(Fuzziness.EditDistance(1))

                                .Boost(0.5)
                                )
                            , must => must.Bool(bo => bo
                                .Should(sh => sh
                                    // new wildcard search
                                    .DisMax(d => d
                                        .Boost(100)
                                        .Queries(qs => qs
                                                .MatchPhrase(m => m   // exact match -- highest boost
                                                .Field("last_name")
                                                .Query(lastName)
                                                .Analyzer("standard")
                                                .Boost(100.0)
                                            )
                                             , qs => qs.MatchPhrase(m => m   // exact alternate name match -- highest boost
                                                .Field("alternate_names")
                                                .Query(lastName)
                                                .Analyzer("standard")
                                                .Boost(1.0)
                                            )
                                             , qs => qs.ConstantScore(c => c
                                                    .Filter(qu => qu
                                                    .QueryString(m => m // wildcard match 
                                                        .Query(lastName)
                                                        .DefaultField("last_name")
                                                    )
                                                )
                                                .Boost(0.9)
                                            )
                                              , qs => qs.ConstantScore(c => c
                                                    .Filter(qu => qu
                                                    .QueryString(m => m // wildcard match on alt names
                                                        .Query(lastName)
                                                        .DefaultField("alternate_names")
                                                    )
                                                )
                                                .Boost(0.5)
                                            )
                                             , qs => qs.ConstantScore(c => c
                                                    .Filter(qu => qu
                                                    .Match(m => m   // fuzzy match -- least boost
                                                        .Field("last_name")
                                                        .Query(lastName)
                                                            .Fuzziness(Fuzziness.EditDistance(1))
                                                        .Analyzer("standard")
                                                        .PrefixLength(1)
                                                    )
                                                )
                                                .Boost(0.01)
                                            )
                                             , qs => qs.ConstantScore(c => c
                                                    .Filter(qu => qu
                                                    .Match(m => m   // fuzzy match on alternate names -- least boost
                                                        .Field("alternate_names")
                                                        .Query(lastName)
                                                            .Fuzziness(Fuzziness.EditDistance(1))
                                                        .Analyzer("standard")
                                                        .PrefixLength(1)
                                                    )
                                                )
                                                .Boost(0.001)
                                            )
                                        )
                                    )
                                      , sh => sh.DisMax(d => d
                                        .Boost(0.1)
                                        .Queries(qs => qs
                                                .MatchPhrase(m => m   // exact match -- highest boost
                                                .Field("first_name")
                                                .Query(firstName)
                                                .Analyzer("standard")
                                                .Boost(100.0)
                                            )
                                            , qs => qs.ConstantScore(c => c
                                                    .Filter(qu => qu
                                                    .QueryString(m => m // wildcard match 
                                                        .Query(firstName)
                                                        .DefaultField("first_name")
                                                    )
                                                )
                                                .Boost(0.1)
                                            )
                                            , qs => qs.ConstantScore(c => c
                                                    .Filter(qu => qu
                                                    .Match(m => m   // fuzzy match -- least boost
                                                        .Field("first_name")
                                                        .Query(firstName)
                                                            .Fuzziness(Fuzziness.EditDistance(1))
                                                        .Analyzer("standard")
                                                        .PrefixLength(1)
                                                    )
                                                )
                                                .Boost(0.01)
                                            )
                                        )
                                    )
                                        , sh => sh.DisMax(d => d
                                        .Queries(qs => qs
                                                .MatchPhrase(m => m   // exact
                                                .Field("last_name")
                                                    .Query(lastNameExact)
                                                   // .Fuzziness(Fuzziness.EditDistance(0))
                                                .Analyzer("standard")
                                                .Boost(100)
                                            )
                                            , qs => qs.MatchPhrase(m => m   // exact
                                                .Field("alternate_names")
                                                .Query(lastNameExact)
                                                   // .Fuzziness(Fuzziness.EditDistance(0))
                                                .Analyzer("standard")
                                                .Boost(0.1)
                                            )
                                        )
                                    )
                                        , sh => sh.DisMax(d => d
                                        .Boost(100)
                                        .Queries(qs => qs
                                            .QueryString(m => m // wildcard match 
                                                .Query(lastNameExactWildcard)
                                                .DefaultField("last_name")
                                                .Analyzer("standard")
                                                // .FuzzyMinSim(0.0)
                                                .Boost(100)
                                            )
                                            , qs => qs.QueryString(m => m // wildcard match 
                                                .Query(lastNameExactWildcard)
                                                .DefaultField("alternate_names")
                                                .Analyzer("standard")
                                                //   .FuzzyMinSim(0.0)
                                                .Boost(0.1)
                                            )
                                        )
                                    )
                                        , sh => sh.DisMax(d => d
                                        .Queries(qs => qs
                                                .MatchPhrase(m => m   // exact
                                                .Field("first_name")
                                                .Query(firstNameExact)
                                                   //.Fuzziness(Fuzziness.EditDistance(0))
                                                .Analyzer("standard")
                                                .Boost(2.0)
                                            )
                                        )
                                    )
                                        , sh => sh.DisMax(d => d
                                        .Boost(0.1)
                                        .Queries(qs => qs
                                            .QueryString(m => m // wildcard match 
                                                .Query(firstNameExactWildcard)
                                                .DefaultField("first_name")
                                                .Analyzer("standard")
                                                //      .FuzzyMinSim(0.0)
                                                .Boost(0.5)
                                                    .DefaultOperator(Operator.And)
                                            )
                                        )
                                    )
                                    ).MinimumShouldMatch(numNames)
                            )
                    #endregion

                    #region Relationships
         , must => must.Raw(getSoundex(must, relationshipsLastSoundex))
                        // new wildcard search
                           , must => must.Raw(getDisMaxName(must, 
              "relationships.last_name", relationshipsLast))
                           , must => must.Raw(getDisMaxName(must, 
               "relationships.first_name", relationshipsFirst))
                           , must => must.Raw(getDisMaxNameExact(must, 
            "relationships.first_name", relationshipsFirstExact))
                           , must => must.Raw(getDisMaxNameExact(must, 
             "relationships.last_name", relationshipsLastExact))
                    #endregion
                , must => must.Raw(keywordstring)
                            )
                        )
                    ).Should(sh => sh
                                        .Match(m => m
                                            .Field("record_type.name.raw")
                                            .Query(recordType)
                                            .Boost(100)))
                    .Filter(f => f
                        .Bool(b => b.Must(a => a
                            .Bool(bm => bm.Should(
                                sh => sh.Range(r => r
                                    .Field("start_year")
                                    .GreaterThanOrEquals(startYear)
                                    .LessThanOrEquals(endYear)
                                ),
                                sh => sh.Range(r => r
                                    .Field("end_year")
                                    .GreaterThanOrEquals(startYear)
                                    .LessThanOrEquals(endYear)
                                    )
                            )),
                            a => a.Range(r => r
                                .Field("image_id")
                                .GreaterThanOrEquals(dHasImages)
                            ),
                            a => a.Terms(t => t.Field("collection.id").Terms(freeCollectionIds)),
                            a => a.Terms(t => t.Field("collection.id").Terms(favorites)),
                            //TODO: update for nested Attribute type
                            a => a.Term(t => t.Field("volume_id").Value(volumeId)),
                            a => a.Term(t => t.Field("page_id").Value(pageId)),
                            a => a.Term(t => t.Field("page_name.raw").Value(pageName)),
                            a => a.Term(t => t.Field("collection.name.raw").Value(databaseName)),
                            a => a.Term(t => t.Field("record_type.name.raw").Value(recordTypeExact)),
                            a => a.Term(t => t.Field("collection.category.name.raw").Value(category))
                        )
                    )
                )
            );
...