Skip to content

Empty index corrupts sort order #8226

Closed
@matthughes

Description

@matthughes

I've been trying to track down some strange sorting results and have narrowed it down to having an empty index. I have multiple indexes all aliased to the same value. Sort order works fine, but once you add an empty index, the order is corrupted. Reproduction below:

#!/bin/bash

# Create index with no docs with alias test
curl -s -XPOST "http://localhost:9200/test-1"     -d '{ "aliases" : { "test" : {} }}' > /dev/null

# Then create a bunch of indices with alias test
curl -s XPOST "http://localhost:9200/test-2"     -d '{ "aliases" : { "test" : {} }}' > /dev/null
curl -s -XPOST "http://localhost:9200/test-2/doc" -d "{ \"entry\": 1 }"

curl -s -XPOST "http://localhost:9200/test-3"     -d '{ "aliases" : { "test" : {} }}' > /dev/null
curl -s -XPOST "http://localhost:9200/test-3/doc" -d "{ \"entry\": 2 }"

curl -s -XPOST "http://localhost:9200/test-4"     -d '{ "aliases" : { "test" : {} }}' > /dev/null
curl -s -XPOST "http://localhost:9200/test-4/doc" -d "{ \"entry\": 3 }"

curl -s -XPOST "http://localhost:9200/test-5"     -d '{ "aliases" : { "test" : {} }}' > /dev/null
curl -s -XPOST "http://localhost:9200/test-5/doc" -d "{ \"entry\": 4 }"

curl -s -XPOST "http://localhost:9200/test-6"     -d '{ "aliases" : { "test" : {} }}' > /dev/null
curl -s -XPOST "http://localhost:9200/test-6/doc" -d "{ \"entry\": 5 }"

curl -s -XPOST "http://localhost:9200/test-7"     -d '{ "aliases" : { "test" : {} }}' > /dev/null
curl -s -XPOST "http://localhost:9200/test-7/doc" -d "{ \"entry\": 6 }"

sleep 2

# Perform a sorted query, descending on field 'entry'
curl -XPOST 'http://localhost:9200/test/_search?pretty' -d '{
  "query": {
    "filtered": {
      "query": {
        "bool": {
          "should": [
            {
              "query_string": {
                "query": "*"
              }
            }
          ]
        }
      },
      "filter": {
        "bool": {
          "must": [
            {
              "match_all": {}
            }
          ]
        }
      }
    }
  },
  "highlight": {
    "fields": {},
    "fragment_size": 2147483647,
    "pre_tags": [
      "@start-highlight@"
    ],
    "post_tags": [
      "@end-highlight@"
    ]
  },
  "size": 500,
  "sort": [
    {
      "entry": {
        "order": "desc",
        "ignore_unmapped": true
      }
    }
  ]
}' | jq ".hits.hits[] | ._source.entry"

Results:

5
1
3
2
6
4

I can fix sort order in two ways: 1) remove the empty index or 2) change "ignore_unmapped" to false.

But IMO an empty index should no affect sort results. I'm also confused on why "ignore_unmapped": false, fixes things. I would think you would want the reverse, but it fails when true.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions