0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Aerospike Go ClientでQueryがNode: Index not foundというエラーが出る

Last updated at Posted at 2023-06-20

はじめに

仕事で利用しているツールを回収する際に、Aerospikeからデータを取得するのに苦戦したのでまとめます

問題

	stm := aerospike.NewStatement("test", "log", "user", "timestamp")
	stm.SetFilter(aerospike.NewRangeFilter("timestamp", from, to))
	recordset, err := client.Query(nil, stm)
	if err != nil {
		fmt.Println("Query error:", err)
	}
	defer recordset.Close()

	for res := range recordset.Results() {
		if res.Err != nil {
            // ここでエラーが発生する
			fmt.Println("Result error:", res.Err)
		} else {
			fmt.Println(res.Record.Bins)
		}
	}

上のコードを実行すると以下のエラーが出ます

Node BB9020011AC4202 127.0.0.1:3000: Index not found

おそらくAerospikeからデータがうまくとれていないからだとこの時点で予測しました

解決方法

インデックスが正しく作成されていないのが原因でした
Aerospikeのコンテナに入り、インデックスを作成するとうまく動きました

$ docker exec -it as-log sh
$ aql
$ SHOW INDEXES
$ CREATE INDEX idx_timestamp ON test.log (timestamp) NUMERIC
$ SHOW INDEXES

+--------+-------------+-----------+--------------+-------+-------------------+-------------+-----------+
| ns     | bin         | indextype | set          | state | indexname         | path        | type      |
+--------+-------------+-----------+--------------+-------+-------------------+-------------+-----------+
| "test" | "timestamp" | "NONE"    | "log" | "RW"  | "timestamp_index" | "timestamp" | "NUMERIC" |
+--------+-------------+-----------+--------------+-------+-------------------+-------------+-----------+

おまけ

Queryのドキュメントを見ると以下の文章があります

This method is only supported by Aerospike 3+ servers. If the policy is nil, the default relevant policy will be used.

これをみてaerospike-server 3系でないと動かない!?と勘違いしました
それ以上ならだいじょうぶです

おわりに

色々デバックをしてここまで行き着くのが大変でした
Aerospikeのコンテナでもつまづいているので別記事で作りました

参考

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?