Elasticsearch で alias を使用しての index 切替を試していたのですが、
切替を実行後、Elasticsearch の search api
へ、検索を投げた所、
検索結果が0件になってしまい結果が返って来なくなりました。
切替前のfield
名と切替後のfield
名は基本的には同じ状態(1つだけ field
追加しました)なので、
切替前の query
で問題ないかと思っていたのですが、検索結果は0件でした。
実施する前の状態と実施後の状態は下記になります。
1. index 切替前
# index 一覧 GET _cat/indices green open index-v1 abcdefghijklmnopqrstu 5 1 1000 0 90.0mb 90.0mb ← テーブル名以外は適当です green open index-v2 abcdefghijklmnopqrstu 5 1 2000 0 90.0mb 90.0mb ← テーブル名以外は適当です
# alias 一覧 GET alias-name/_alias { "index-v1" : { "aliases" : { "alias-name" : { } } } }
# id 検索 GET alias-name/type-name/id0001 又は GET index-v1/type-name/id0001 { "_index" : "index-v1", "_type" : "type-name", "_id" : "id0001", "_version" : 1, "_seq_no" : 0, "_primary_term" : 1, "found" : true, "_source" : { "id" : "id0001", "name" : "Test Name 1", ・ ・ ・ } }
# search api 検索(query 無し) GET alias-name/_search 又は GET index-v1/_search { "took" : 9000, "timed_out" : false, "_shards" : { ・ ・ ・ }, "hits" : { "total" : { "value" : 1000, "relation" : "eq" }, "max_score" : 1.0, "hits" : [ { "_index" : "index-v1", "_type" : "type-name", "_id" : "id0001", "_score" : 1.0, "_source" : { "id" : "id0001", "name" : "Test Name 1", ・ ・ ・ } }, { "_index" : "index-v1", "_type" : "type-name", "_id" : "id0002", "_score" : 1.0, "_source" : { "id" : "id0002", "name" : "Test Name 2", ・ ・ ・ } }, { "_index" : "index-v1", "_type" : "type-name", "_id" : "id0003", "_score" : 1.0, "_source" : { "id" : "id0003", "name" : "Test Name 3", ・ ・ ・ } }, 以下取得件数分繰り返し ・ ・ ・ } ] } }
# search api 検索(query 有り) GET alias-name/_search 又は GET index-v1/_search { "query": { "bool": { "must": { "match_all": {} }, "filter": [ { "term": { "id": "id0002" } } ] } } }
--- 取得結果 --- { "took" : 2, "timed_out" : false, "_shards" : { ・ ・ ・ }, "hits" : { "total" : { "value" : 1, "relation" : "eq" }, "max_score" : 1.0, "hits" : [ { "_index" : "index-v1", "_type" : "type-name", "_id" : "id0002", "_score" : 1.0, "_source" : { "id" : "id0002", "name" : "Test Name 2", ・ ・ ・ } } ] } }
2. index 切替
※ 事前に bulk insert
でindex-v2
というindex名で構築済み
# alias 切替 POST _aliases { "actions": [ { "remove": { "index": "index-v1", "alias": "alias-name" } }, { "add": { "index": "index-v2", "alias": "alias-name" } } ] }
# 古いindex 削除 DELETE index-v1 { "acknowledged" : true }
3. index 切替後
# 古いindex 削除確認 GET _cat/indices green open index-v2 abcdefghijklmnopqrstu 5 1 2000 0 90.0mb 90.0mb
# alias が切り替わってる事を確認 GET alias-name/_alias { "index-v2" : { "aliases" : { "alias-name" : { } } } }
# id 検索 GET alias-name/_doc/id0001 又は GET index-v2/_doc/id0001 { "_index" : "index-v2", "_type" : "_doc", "_id" : "id0001", "_version" : 1, "_seq_no" : 0, "_primary_term" : 1, "found" : true, "_source" : { "id" : "id0001", "name" : "Test Name 1", ・ ・ ・ } }
# search api 検索(query 無し) GET alias-name/_search 又は GET index-v2/_search { "took" : 1, "timed_out" : false, "_shards" : { ・ ・ ・ }, "hits" : { "total" : { "value" : 2000, "relation" : "eq" }, "max_score" : 1.0, "hits" : [ { "_index" : "index-v2", "_type" : "_doc", "_id" : "id0001", "_score" : 1.0, "_source" : { "id" : "id0001", "name" : "Test Name 1", ・ ・ ・ } }, { "_index" : "index-v2", "_type" : "_doc", "_id" : "id0002", "_score" : 1.0, "_source" : { "id" : "id0002", "name" : "Test Name 2", ・ ・ ・ } }, { "_index" : "index-v2", "_type" : "_doc", "_id" : "id0003", "_score" : 1.0, "_source" : { "id" : "id0003", "name" : "Test Name 3", ・ ・ ・ } }, 以下取得件数分繰り返し ・ ・ ・ } ] } }
# search api 検索(query 有りかつ match_all:{} の場合) GET alias-name/_search 又は GET index-v2/_search { "query": { "bool": { "must": { "match_all": {} } } } }
--- 取得結果 --- { "took" : 2, "timed_out" : false, "_shards" : { ・ ・ ・ }, "hits" : { "total" : { "value" : 1, "relation" : "eq" }, "max_score" : 1.0, "hits" : [ { "_index" : "index-v2", "_type" : "_doc", "_id" : "id0001", "_score" : 1.0, "_source" : { "id" : "id0001", "name" : "Test Name 1", ・ ・ ・ } }, 以下取得件数分繰り返し ・ ・ ・ } ] } }
# search api 検索(query 有りかつ filter 指定有りの場合) GET alias-name/_search 又は GET index-v2/_search { "query": { "bool": { "must": { "match_all": {} }, "filter": [ { "term": { "id": "id0002" } } ] } } }
--- 取得結果 --- { "took" : 0, "timed_out" : false, "_shards" : { ・ ・ ・ }, "hits" : { "total" : { "value" : 0, "relation" : "eq" }, "max_score" : null, "hits" : [ ] } }
と、上記の様に filter 有りだと 検索結果が0件になります。
alias
やsetting
やmapping
の定義に問題があるのか、bulk insert
時に問題があるのか原因がわからずです。
どなたか、ご教示頂けると助かります。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。