Different results of aggregation query on same version

I am running the following query on multiple servers, same build (same hash, build date, and version number) of ES.
7.16.2

{
  "size": 0,
  "query": {
    "terms": {       
      "FileFeedID": [
        // Some values
      ]
    }
  },
  "aggs": {
    "missing_values": {
      "scripted_metric": {
        "init_script": "state.FileFeedIDs = [:]",
        "map_script": "def filefeedId = doc['FileFeedID'].value; if (!state.FileFeedIDs.containsKey(filefeedId)) { state.FileFeedIDs[filefeedId] = 0; } state.FileFeedIDs[filefeedId]++;",
        "combine_script": " return state.FileFeedIDs;",
        "reduce_script": " def fileFeeds = new HashSet(); for (state in states) { fileFeeds.addAll(state.keySet()); } def missing = []; for (fileFeedId in params.FileFeedID) { if (!fileFeeds.contains(fileFeedId)) { missing.add(fileFeedId); } } return missing; ",
        "params": {
          "FileFeedID": [
            // Some values
          ]
        }
      }
    }
  }
}

In one server, this operates fine and produces no error. On the other...

{
   "error": {
   	"root_cause": [
   		{
   			"type": "class_cast_exception",
   			"reason": "class_cast_exception: class java.lang.Long cannot be cast to class java.lang.String (java.lang.Long and java.lang.String are in module java.base of loader 'bootstrap')"
   		},
   		{
   			"type": "class_cast_exception",
   			"reason": "class java.lang.Long cannot be cast to class java.lang.String (java.lang.Long and java.lang.String are in module java.base of loader 'bootstrap')"
   		}
   	],
   	"type": "search_phase_execution_exception",
   	"reason": "all shards failed",
   	"phase": "query",
   	"grouped": true,
   	"failed_shards": [
   		{
   			"shard": 0,
   			"index": "filefeed",
   			"node": "NODE1_REDACTCED",
   			"reason": {
   				"type": "class_cast_exception",
   				"reason": "class_cast_exception: class java.lang.Long cannot be cast to class java.lang.String (java.lang.Long and java.lang.String are in module java.base of loader 'bootstrap')"
   			}
   		},
   		{
   			"shard": 1,
   			"index": "filefeed",
   			"node": "NODE2_REDACTED",
   			"reason": {
   				"type": "class_cast_exception",
   				"reason": "class java.lang.Long cannot be cast to class java.lang.String (java.lang.Long and java.lang.String are in module java.base of loader 'bootstrap')"
   			}
   		}
   	]
   },
   "status": 500
}

One possible issue was that this _search query needed .keyword specified on the term. TODO: Verify this was the root cause.

1 Like

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