Hello,
I am trying to paginate a search but I am unable to do so because results don't include the sort
field to search after. However, from what I understand reading the search_after
documentation Paginate search results | Elasticsearch Guide [7.12] | Elastic the tie breaker
sort field should have been added implicitly.
All PIT search requests add an implicit sort tiebreaker field called _shard_doc, which can also be provided explicitly.
I do the following actions on a 7.12 one-node cluster. Is there something I do wrong ? Or I misunderstood that part of the documentation ?
I create an index with 2 documents:
POST /post/_doc
{
"author": "alice dupont",
"title": "Let's go to Mars"
}
POST /post/_doc
{
"author": "bob benkhen",
"title": "Let's go to the Moon"
}
I create a PIT on the index:
POST /post/_pit?keep_alive=2m
If I make a search using the PIT, I get a hit without a sort
field:
{
"pit": {
"id": "PIT"
},
"size": 1
}
{
"_shards": {
"failed": 0,
"skipped": 0,
"successful": 1,
"total": 1
},
"hits": {
"hits": [
{
"_id": "2Ff1F3kBfAqWnfewA6Um",
"_index": "post",
"_score": 1.0,
"_source": {
"author": "alice dupont",
"title": "Let's go to Mars"
},
"_type": "_doc"
}
],
"max_score": 1.0,
"total": {
"relation": "eq",
"value": 2
}
},
"pit_id": "PIT",
"timed_out": false,
"took": 1
}
However, if I add the tie breaker sort field explicitly, I do have the sort
field as part of the hits. My understanding was that this sort field would be added by Elasticsearch automatically.
GET _search
{
"pit": {
"id": "PIT"
},
"size": 1,
"sort": {
"_shard_doc": "asc"
}
}
{
"_shards": {
"failed": 0,
"skipped": 0,
"successful": 1,
"total": 1
},
"hits": {
"hits": [
{
"_id": "2Ff1F3kBfAqWnfewA6Um",
"_index": "post",
"_score": null,
"_source": {
"author": "alice dupont",
"title": "Let's go to Mars"
},
"_type": "_doc",
"sort": [
0
]
}
],
"max_score": null,
"total": {
"relation": "eq",
"value": 2
}
},
"pit_id": "PIT",
"timed_out": false,
"took": 1
}