私はupdate apiを使用しようとしました。私はリストを含む文書を挿入しました。フィールドの括弧を許可しないElasticsearchスクリプトの名前
INSERT:
curl -XPOST "http://localhost:9200/t/t/1" -d'
{
"hobbies(first)" : ["a", "b"]
}'
更新クエリ:
curl -XPOST localhost:9200/t/t/1/_update?pretty -d '{ "script" : {
"inline": "ctx._source.hobbies(first).add(params.new_hobby)",
"params" : {
"new_hobby" : "c"
}
}
}'
ERROR:私はリストを更新しようとしたとき
{
"error" : {
"root_cause" : [
{
"type" : "remote_transport_exception",
"reason" : "[aaBiwwv][172.17.0.2:9300][indices:data/write/update[s]]"
}
],
"type" : "illegal_argument_exception",
"reason" : "failed to execute script",
"caused_by" : {
"type" : "script_exception",
"reason" : "compile error",
"caused_by" : {
"type" : "illegal_argument_exception",
"reason" : "Variable [first] is not defined."
},
"script_stack" : [
"ctx._source.hobbies(first).add(params.new_hob ...",
" ^---- HERE"
],
"script" : "ctx._source.hobbies(first).add(params.new_hobby)",
"lang" : "painless"
}
},
"status" : 400
}
、私は上記のエラーを持っています。自分のフィールド名から角括弧('(first)')を削除したときに機能していることに気付きました。大括弧で囲まれたフィールド名で更新クエリを準備するにはどうすればよいですか?
ありがとうございます。
括弧をアンダースコアで置き換えてください。それは間違いなく、ドキュメントの所有権を持つ良い習慣ではありません。 "趣味(最初の)" - >の命名規則について "hobbies_first" グッドリンク: https://www.elastic.co/guide/en/beats/libbeat/current/event-conventions.html – nozari
I私のフィールド名を動的に生成し、会社(company_code)のようなフィールドがあります。これは会社フィールドがcompany_code関係を使って準備されていることを意味していますので、私のフィールドをもっと分かりやすくしようとしています。スクリプトで大括弧を使用する方法がありますか? –
この作業をしようとする代わりに、大括弧をアンダースコアに置き換える関数を作成することをお勧めします。 – nozari