Optimize bool filter query

Hi, I'm using ES 7.10 deployed in Elastic Cloud. I developed a Java application that use High Level REST client.

I want to make a query like this:

index >=1.67 && index<=1.67
AND
(sphereMin<=-7 && sphereMax >=-7 && cylinderMin<=0 && cylinderMax>=-6
OR
sphereMin<=-7 && sphereMax>=-13 && cylinderMin<=6 && cylinderMax>=0)

I don't need a score for this query. I want just to get data from my index. The query generated using the API is this:

{
  "bool" : {
    "filter" : [
      {
        "bool" : {
          "should" : [
            {
              "range" : {
                "index" : {
                  "from" : "1.67",
                  "to" : "1.67",
                  "include_lower" : true,
                  "include_upper" : true,
                  "boost" : 1.0
                }
              }
            }
          ],
          "adjust_pure_negative" : true,
          "boost" : 1.0
        }
      },
      {
        "bool" : {
          "should" : [
            {
              "bool" : {
                "filter" : [
                  {
                    "bool" : {
                      "filter" : [
                        {
                          "range" : {
                            "sphereMin" : {
                              "from" : null,
                              "to" : -7,
                              "include_lower" : true,
                              "include_upper" : true,
                              "boost" : 1.0
                            }
                          }
                        },
                        {
                          "range" : {
                            "sphereMax" : {
                              "from" : -7,
                              "to" : null,
                              "include_lower" : true,
                              "include_upper" : true,
                              "boost" : 1.0
                            }
                          }
                        }
                      ],
                      "adjust_pure_negative" : true,
                      "boost" : 1.0
                    }
                  },
                  {
                    "bool" : {
                      "filter" : [
                        {
                          "range" : {
                            "cylinderMin" : {
                              "from" : null,
                              "to" : 0,
                              "include_lower" : true,
                              "include_upper" : true,
                              "boost" : 1.0
                            }
                          }
                        },
                        {
                          "range" : {
                            "cylinderMax" : {
                              "from" : -6,
                              "to" : null,
                              "include_lower" : true,
                              "include_upper" : true,
                              "boost" : 1.0
                            }
                          }
                        }
                      ],
                      "adjust_pure_negative" : true,
                      "boost" : 1.0
                    }
                  }
                ],
                "adjust_pure_negative" : true,
                "boost" : 1.0
              }
            },
            {
              "bool" : {
                "filter" : [
                  {
                    "bool" : {
                      "filter" : [
                        {
                          "range" : {
                            "sphereMin" : {
                              "from" : null,
                              "to" : -7,
                              "include_lower" : true,
                              "include_upper" : true,
                              "boost" : 1.0
                            }
                          }
                        },
                        {
                          "range" : {
                            "sphereMax" : {
                              "from" : -13,
                              "to" : null,
                              "include_lower" : true,
                              "include_upper" : true,
                              "boost" : 1.0
                            }
                          }
                        }
                      ],
                      "adjust_pure_negative" : true,
                      "boost" : 1.0
                    }
                  },
                  {
                    "bool" : {
                      "filter" : [
                        {
                          "range" : {
                            "cylinderMin" : {
                              "from" : null,
                              "to" : 6,
                              "include_lower" : true,
                              "include_upper" : true,
                              "boost" : 1.0
                            }
                          }
                        },
                        {
                          "range" : {
                            "cylinderMax" : {
                              "from" : 0,
                              "to" : null,
                              "include_lower" : true,
                              "include_upper" : true,
                              "boost" : 1.0
                            }
                          }
                        }
                      ],
                      "adjust_pure_negative" : true,
                      "boost" : 1.0
                    }
                  }
                ],
                "adjust_pure_negative" : true,
                "boost" : 1.0
              }
            }
          ],
          "adjust_pure_negative" : true,
          "boost" : 1.0
        }
      }
    ],
    "adjust_pure_negative" : true,
    "boost" : 1.0
  }
}

Do you see space for improvements? The query seems correct but I don't understand well if it's the more convenient to do. Do you have some hint about it?

Thanks

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.