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

Adding "routing" setting for an alias via POST _aliases has different behavior than PUT (single alias) #5465

Closed
sujal opened this issue Mar 19, 2014 · 0 comments

Comments

@sujal
Copy link

sujal commented Mar 19, 2014

Hi there,

I've noticed an issue that either points to me misunderstanding something about routing in Elasticsearch or a subtle bug in elasticsearch itself. Here's what I'm trying to do:

When trying to create aliases, we noticed that the routing parameter was getting dropped from our alias's definition. Since we put documents into the index with the routing param, but only query using the alias, documents weren't getting returned most of the time even if they were in the index.

Upon debugging, we found that the POST _aliases endpoint silently drops the routing parameter if it's an integer, but honors it if it's a string. Oddly, though, the PUT endpoint to create a single alias works for a string or numeric routing param.

See the test case below.

curl -X PUT 'http://localhost:9200/test1?pretty'

curl -X POST 'http://localhost:9200/_aliases?pretty' -d '{
  "actions":[
    {
      "add":{
        "index":"test1",
        "alias":"test1_1",
        "routing":1,
        "filter":{
          "term":{
            "user_id":1
          }
        }
      }
    }
  ]
}'


curl -X GET 'http://localhost:9200/_alias/test1_1?pretty'
#2014-03-19T14:07:28-04:00 [200] (0.002s)
#
# {
#   "test1":{
#     "aliases":{
#       "test1_1":{
#         "filter":{
#           "term":{
#             "user_id":1
#           
# }
#         }
#       }
#     }
#   }
# }


curl -X DELETE 'http://localhost:9200/test1/_alias/test1_1?pretty'

curl -X PUT 'http://localhost:9200/test1/_alias/test1_1?pretty' -d '{
  "routing":1,
  "filter":{
    "term":{
      "user_id":1
    }
  }
}'

curl -X GET 'http://localhost:9200/_alias/test1_1?pretty'
#2014-03-19T14:07:28-04:00 [200] (0.002s)
#
# {
#   "test1":{
#     "aliases":{
#       "test1_1":{
#         "filter":{
#           "term":{
#             "user_id":1
#           
# }
#         },
#         "index_routing":"1",
#         "search_routing":"1"
#       }
#     }
#   }
# }

# NOW try a STRING for routing

curl -X DELETE 'http://localhost:9200/test1/_alias/test1_1?pretty'

curl -X POST 'http://localhost:9200/_aliases?pretty' -d '{
  "actions":[
    {
      "add":{
        "index":"test1",
        "alias":"test1_1",
        "routing":"1",
        "filter":{
          "term":{
            "user_id":1
          }
        }
      }
    }
  ]
}'

curl -X GET 'http://localhost:9200/_alias/test1_1?pretty'
# {
#   "test1" : {
#     "aliases" : {
#       "test1_1" : {
#         "filter" : {
#           "term" : {
#             "user_id" : 1
#           }
#         },
#         "index_routing" : "1",
#         "search_routing" : "1"
#       }
#     }
#   }
# }


Our ES version we're testing against:

curl -XGET 'http://localhost:9200'

which returns:

{
  "status" : 200,
  "name" : "Jamie Braddock",
  "version" : {
    "number" : "1.0.1",
    "build_hash" : "5c03844e1978e5cc924dab2a423dc63ce881c42b",
    "build_timestamp" : "2014-02-25T15:52:53Z",
    "build_snapshot" : false,
    "lucene_version" : "4.6"
  },
  "tagline" : "You Know, for Search"
}

Here's the ruby program we initially used to debug inside the Rails console (easier to change the routing param from int to string - i just cut & pasted the curl commands from our logging there. Guess I could set an ENV var for the shell stuff, but I leave that to the user 😄 )

client = Rails.configuration.elasticsearch

index = "test1"
filter_id = 1
unique_alias_name = "test1_#{filter_id}"
filter_hash = { "term" => { "user_id" => filter_id } }

client.indices.create(index: index)
client.indices.update_aliases body: {
  actions: [
    { add: { index: index, alias: unique_alias_name, routing: filter_id, filter: filter_hash } }
  ]
}

result1 = client.indices.get_alias name: unique_alias_name
puts result1

client.indices.delete_alias index: index, name: unique_alias_name

if client.indices.exists_alias(name: unique_alias_name)
  puts "didn't delete" 
  exit 1
end

client.indices.put_alias index: index, name: unique_alias_name, body: {
  routing: filter_id,
  filter: filter_hash
}

result2 = client.indices.get_alias name: unique_alias_name
puts result2


unless result1 == result2
  puts "Why don't these match!!" 
  exit 1
end
clintongormley added a commit that referenced this issue Mar 20, 2014
Also added REST tests for setting index/search/routing
via the PUT /_aliases endpoint

Fixes #5465
clintongormley added a commit that referenced this issue Mar 20, 2014
Also added REST tests for setting index/search/routing
via the PUT /_aliases endpoint

Fixes #5465
clintongormley added a commit that referenced this issue Mar 20, 2014
Also added REST tests for setting index/search/routing
via the PUT /_aliases endpoint

Fixes #5465
mute pushed a commit to mute/elasticsearch that referenced this issue Jul 29, 2015
Also added REST tests for setting index/search/routing
via the PUT /_aliases endpoint

Fixes elastic#5465
mute pushed a commit to mute/elasticsearch that referenced this issue Jul 29, 2015
Also added REST tests for setting index/search/routing
via the PUT /_aliases endpoint

Fixes elastic#5465
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant