2017-10-26 5 views
0

に予め登録されたmushacheテンプレートでtojson使用方法。 kibanaコンソールでは、検索クエリテンプレートを保存しようとしています。Elasticsearch</p> <p>こんにちは、</p> <p>であらかじめ登録mushacheテンプレートで使用する用語は、私がElasticsearchのv5.6.3を使用する方法Elasticsearch

POST _scripts/test-json 
{ 
    "script": { 
    "lang": "mustache", 
    "source": {"query": {"filter": {"bool": {"must": [{"terms": {"beat.hostname": {{#tojson}}hostname{{/tojson}} } }] } } } } 
    } 
} 

しかし、二重引用符を除いて構文エラーが発生しました。

私はgithubの問題を見ました。 https://github.com/elastic/elasticsearch/issues/21648

この問題でサンプルのようにテンプレートを変更しましたが、構文エラーはありません。しかし、私は結果を得ることができません。コールされた後、私はランタイムエラーを得た、

POST _scripts/test-json 
{ 
    "script": { 
    "lang": "mustache", 
    "source": {"query": {"filter": {"bool": {"must": [{"terms": {"beat.hostname": ["{{#tojson}}hostname{{/tojson}}}}"] } }] } } } } 
    } 
} 

POST _scripts/test-json 
{ 
    "script": { 
    "lang": "mustache", 
    "source": {"query": {"filter": {"bool": {"must": [{"terms": {"beat.hostname": ["{{hostname}}"] } }] } } } } 
    } 
} 

そして、私は、テンプレートを変更しました。

{ 
    "type": "json_parse_exception", 
    "reason": "Unexpected character ('h' (code 104)): was expecting comma to separate Array entries\n at [Source: org.elasticsear[email protected]396f6738; line: 1, column: 190]" 
    } 

事前登録された検索テンプレートの用語にいくつかのパラメータを送信するにはどうすればよいですか?

ありがとうございます。

答えて

0

この問題は解決されました。キーはscript.sourceで、クエリJSONを含む文字列にすることができます。

POST _scripts/test-json 
{ 
    "script": { 
    "lang": "mustache", 
    "source": "{\"size\": 0, \"query\": {\"bool\": {\"must\": [{\"terms\": {\"beat.hostname\": {{#tojson}}hostname{{/tojson}} } } ] }}}" 
    } 
} 

このスクリプトは成功する可能性があります。そして、以下のようにそれを呼び出す:

GET _search/template 
{ 
    "id": "test-json", 
    "params": { 
    "hostname": ["host-1", "host-2"] 
    } 
} 

ハード

:-)解決策を見つけるために
関連する問題