Division operation in script field is tooooooo slow


(Zhang Ke) #1

Hi,

Different operations in script field lead to quite different performance. In my environment, the below query cost about 400ms.

GET es/_search
{
  "size": 0,
  "aggs": {
    "by_cluster": {
      "terms": {
        "field": "Cluster",
        "size": 10
      },
      "aggs": {
        "by_user": {
          "terms": {
            "field": "User",
            "size": 10
          },
          "aggs": {
            "total_pend": {
              "sum": {
              "field": "Pend Time",
              }
            }
          }
        }
      }
    }
  }
}

When I use script field which contains multiplication operation, the similar query cost about 1100ms.

GET es/_search
{
  "size": 0,
  "aggs": {
    "by_cluster": {
      "terms": {
        "field": "Cluster",
        "size": 10
      },
      "aggs": {
        "by_user": {
          "terms": {
            "field": "User",
            "size": 10
          },
          "aggs": {
            "total_pend": {
              "sum": {
               "script": "doc['Pend Time'].value  * 1000"
              }
            }
          }
        }
      }
    }
  }
}

But when I use script field which contains division operation, the similar query cost about 6000ms which is too slow.

GET es/_search
{
  "size": 0,
  "aggs": {
    "by_cluster": {
      "terms": {
        "field": "Cluster",
        "size": 10
      },
      "aggs": {
        "by_user": {
          "terms": {
            "field": "User",
            "size": 10
          },
          "aggs": {
            "total_pend": {
              "sum": {
               "script": "doc['Pend Time'].value  / 1000",
              }
            }
          }
        }
      }
    }
  }
}

I know the division operation costs much than multiplication operation. But I still wonder why the performance difference is so big.

Any way to improve the divison performance in script field?

Thanks for the help.

Ke


(Zhang Ke) #2

Any idea about this issue?


#3

for the case of integer divide, I think groovy may handle the result as bigdecimal (http://docs.groovy-lang.org/latest/html/documentation/index.html#integer_division).


(Zhang Ke) #4

It is the root cause indeed. Thanks for your help:slightly_smiling:.


(system) #5