Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extra value returned in search response when sort fields are specified along with PIT. #113802

Closed
kiljag opened this issue Sep 30, 2024 · 2 comments
Labels
:Search Foundations/Search Catch all for Search Foundations Team:Search Foundations Meta label for the Search Foundations team in Elasticsearch

Comments

@kiljag
Copy link

kiljag commented Sep 30, 2024

Elasticsearch Version

8.13.4

Installed Plugins

No response

Java Version

bundled

OS Version

Ubuntu

Problem Description

Hi,
When I try to sort the index with PIT, there is an extra value in sort field of the hit, where as the same is not present when the index is not queried without PIT.

Please let me know if this is expected or a bug.
Thank you.

Steps to Reproduce

Create a sample index and add few documents

PUT sample_index
{
  "mappings": {
    "properties": {
      "timestamp": {
        "type": "date"
      }
    }
  }
}
POST sample_index/_create/1
{
  "id": 1, "timestamp": "2024-10-21"
}
POST sample_index/_create/2
{
  "id": 2, "timestamp": "2024-10-22"
}

Search with sort fields without PIT

GET sample_index/_search
{
  
    "sort": [
    {
      "timestamp": {
        "order": "desc"
      }
    },
    {
      "id": {
        "order": "desc"
      }
    }
  ]
}

Response

"hits": [
      {
        "_index": "sample_index",
        "_id": "2",
        "_score": null,
        "_source": {
          "id": 2,
          "timestamp": "2024-10-22"
        },
        "sort": [
          1729555200000,
          2
        ]
      },
      {
        "_index": "sample_index",
        "_id": "1",
        "_score": null,
        "_source": {
          "id": 1,
          "timestamp": "2024-10-21"
        },
        "sort": [
          1729468800000,
          1
        ]
      }
    ]

Search with sort fields along with PIT

POST sample_index/_pit?keep_alive=1m
GET /_search
{
  "pit": {
    "id": "ucyMBAEMc2FtcGxlX2luZGV4Fl9KMzhxN1NrUUVLb0NJMF9FVUY0UFEAFjREbjM3VlVqUl9xX2xDU05NNGVWZkEAAAAAAABHwAwWOXlNbERIZXlRSldCRTZJX1R5MUxtZwABFl9KMzhxN1NrUUVLb0NJMF9FVUY0UFEAAA==",
    "keep_alive": "1m"
  }, 
  "sort": [
    {
      "timestamp": {
        "order": "desc"
      }
    },
    {
      "id": {
        "order": "desc"
      }
    }
  ]
}

Response

"hits": [
      {
        "_index": "sample_index",
        "_id": "2",
        "_score": null,
        "_source": {
          "id": 2,
          "timestamp": "2024-10-22"
        },
        "sort": [
          1729555200000,
          2,
          1 <== EXTRA_FIELD
        ]
      },
      {
        "_index": "sample_index",
        "_id": "1",
        "_score": null,
        "_source": {
          "id": 1,
          "timestamp": "2024-10-21"
        },
        "sort": [
          1729468800000,
          1,
          0 <== EXTRA_FIELD
        ]
      }
    ]

When the index is sorted using PIT, there is an extra field at 3rd index, where as the same is not present when simple sorting is applied. Is this expected?

Thank you.

Logs (if relevant)

No response

@kiljag kiljag added >bug needs:triage Requires assignment of a team area label labels Sep 30, 2024
@benwtrent benwtrent added the :Search Foundations/Search Catch all for Search Foundations label Oct 2, 2024
@elasticsearchmachine elasticsearchmachine added the Team:Search Foundations Meta label for the Search Foundations team in Elasticsearch label Oct 2, 2024
@elasticsearchmachine
Copy link
Collaborator

Pinging @elastic/es-search-foundations (Team:Search Foundations)

@elasticsearchmachine elasticsearchmachine removed the needs:triage Requires assignment of a team area label label Oct 2, 2024
@smalyshev
Copy link
Contributor

I think the extra value is _shard_doc, from here: https://www.elastic.co/guide/en/elasticsearch/reference/8.15/paginate-search-results.html

All PIT search requests add an implicit sort tiebreaker field called _shard_doc, which can also be provided explicitly. If you cannot use a PIT, we recommend that you include a tiebreaker field in your sort. This tiebreaker field should contain a unique value for each document. If you don’t include a tiebreaker field, your paged results could miss or duplicate hits.

@smalyshev smalyshev removed the >bug label Oct 9, 2024
@smalyshev smalyshev closed this as not planned Won't fix, can't repro, duplicate, stale Oct 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
:Search Foundations/Search Catch all for Search Foundations Team:Search Foundations Meta label for the Search Foundations team in Elasticsearch
Projects
None yet
Development

No branches or pull requests

4 participants