Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Elasticsearch 7.7 broken query

This was working on 7.6.2 but since upgrading to 7.7 it has stopped working and do not know why?

I am doing a query with a nested or with a nested must so it has to be 5 5 5 or 6 6 6 on three columns.

I am using the laravel scout driver for elastic search babenkoivan/scout-elasticsearch-driver

Thanks :)!

  "query": {
    "bool": {
      "must": [
        {
          "bool": {
            "should": [
              {
                "bool": {
                  "must": [
                    [
                      {
                        "term": {
                          "section": "205"
                        }
                      },
                      {
                        "term": {
                          "profile": "40"
                        }
                      },
                      {
                        "term": {
                          "rim_size": "17"
                        }
                      }
                    ]
                  ]
                }
              }
            ]
          }
        },
        {
          "bool": {
            "should": [
              [
                {
                  "term": {
                    "supplier_id": 3
                  }
                }
              ]
            ]
          }
        }
      ]
    }
  },

Error:

{
   "error":{
      "root_cause":[
         {
            "type":"x_content_parse_exception",
            "reason":"[1:106] [bool] failed to parse field [must]"
         }
      ],
      "type":"x_content_parse_exception",
      "reason":"[1:106] [bool] failed to parse field [must]",
      "caused_by":{
         "type":"x_content_parse_exception",
         "reason":"[1:106] [bool] failed to parse field [should]",
         "caused_by":{
            "type":"x_content_parse_exception",
            "reason":"[1:106] [bool] failed to parse field [must]",
            "caused_by":{
               "type":"illegal_state_exception",
               "reason":"expected value but got [START_ARRAY]"
            }
         }
      }
   },
   "status":400
}
like image 311
eqxDev Avatar asked Sep 08 '20 11:09

eqxDev


1 Answers

You have two nested arrays in your bool/must, you need to remove one:

              "must": [
      >>>       [
                  {
                    "term": {
                      "section": "205"
                    }
                  },
                  {
                    "term": {
                      "profile": "40"
                    }
                  },
                  {
                    "term": {
                      "rim_size": "17"
                    }
                  }
      >>>       ]
              ]

It should look like this instead:

              "must": [
                  {
                    "term": {
                      "section": "205"
                    }
                  },
                  {
                    "term": {
                      "profile": "40"
                    }
                  },
                  {
                    "term": {
                      "rim_size": "17"
                    }
                  }
              ]
like image 170
Val Avatar answered Sep 27 '22 21:09

Val