Skip to content

Partial shard failures for non-string composite after_key values #85928

@astefan

Description

@astefan

Elasticsearch Version

latest from master

Installed Plugins

No response

Java Version

bundled

OS Version

windows

Problem Description

Using composite's after_key with a non-String value to get the next "page" of results in a composite aggregation query results in a parsing exception with the message Cannot set after key in the composite aggregation [keys] - incompatible value in the position 0: invalid value, expected string, got Integer.

At least one of the indices used in the search request does not have a mapping for that specific field.

Steps to Reproduce

PUT /index1

{
	"mappings": {
		"properties": {
			"number": {
				"type":"long"
			},
			"text": {
				"type":"keyword"
			}
		}
	}
}

PUT /index2

{
	"mappings": {
		"properties": {
			"date": {
				"type":"date"
			},
			"text": {
				"type":"keyword"
			}
		}
	}
}

POST /index1/_bulk?refresh

{"index":{"_id":1}}
{"number": 123,"text":"bla"}
{"index":{"_id":2}}
{"number": 100,"text":"test"}
{"index":{"_id":3}}
{"number": 200,"text":"foo"}

POST /index2/_bulk?refresh

{"index":{"_id":1}}
{"text":"bla"}
{"index":{"_id":2}}
{"text":"test"}
{"index":{"_id":3}}
{"text":"foo"}

POST /index*/_search

{
  "size": 0,
  "query": {
	"match_all": {}
  },
  "_source": true,
  "track_total_hits": -1,
  "aggregations": {
    "keys": {
      "composite": {
        "size": 1,
        "sources": [
          {
            "number": {
              "terms": {
                "field": "number",
                "missing_bucket": false,
                "order": "asc"
              }
            }
          },
          {
            "text": {
              "terms": {
                "field": "text",
                "missing_bucket": false,
                "order": "asc"
              }
            }
          }
        ]
      }
    }
  }
}

results in

{
    "took": 1,
    "timed_out": false,
    "_shards": {
        "total": 2,
        "successful": 2,
        "skipped": 0,
        "failed": 0
    },
    "hits": {
        "max_score": null,
        "hits": []
    },
    "aggregations": {
        "keys": {
            "after_key": {
                "number": 100,
                "text": "test"
            },
            "buckets": [
                {
                    "key": {
                        "number": 100,
                        "text": "test"
                    },
                    "doc_count": 1
                }
            ]
        }
    }
}

The next query uses the after_key above:

{
  "size": 0,
  "query": {
	"match_all": {}
  },
  "_source": true,
  "track_total_hits": -1,
  "aggregations": {
    "keys": {
      "composite": {
        "size": 1,
        "sources": [
          {
            "number": {
              "terms": {
                "field": "number",
                "missing_bucket": false,
                "order": "asc"
              }
            }
          },
          {
            "text": {
              "terms": {
                "field": "text",
                "missing_bucket": false,
                "order": "asc"
              }
            }
          }
        ],
        "after": {
          "number": 100,
          "text": "test"
        }
      }
    }
  }
}

And the result is

{
    "took": 1,
    "timed_out": false,
    "_shards": {
        "total": 2,
        "successful": 1,
        "skipped": 0,
        "failed": 1,
        "failures": [
            {
                "shard": 0,
                "index": "index2",
                "node": "EqTUabPYTgKzITFjW5SMiA",
                "reason": {
                    "type": "parse_exception",
                    "reason": "Cannot set after key in the composite aggregation [keys] - incompatible value in the position 0: invalid value, expected string, got Integer",
                    "caused_by": {
                        "type": "illegal_argument_exception",
                        "reason": "incompatible value in the position 0: invalid value, expected string, got Integer",
                        "caused_by": {
                            "type": "illegal_argument_exception",
                            "reason": "invalid value, expected string, got Integer"
                        }
                    }
                }
            }
        ]
    },
    "hits": {
        "max_score": null,
        "hits": []
    },
    "aggregations": {
        "keys": {
            "after_key": {
                "number": 123,
                "text": "bla"
            },
            "buckets": [
                {
                    "key": {
                        "number": 123,
                        "text": "bla"
                    },
                    "doc_count": 1
                }
            ]
        }
    }
}

I would have expected Elasticsearch to ignore the fact that index2 doesn't have that specific field used as after_key.
As is, the behavior is inconsistent: for a string value there is no exception, for a numeric value there are partial shard failures.

Metadata

Metadata

Assignees

No one assigned

    Labels

    >bugTeam:AnalyticsMeta label for analytical engine team (ESQL/Aggs/Geo)

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions