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.

Elastic Cloud の filters の使い方

Last updated at Posted at 2022-04-01

参考ページ
Search API Filters

サンプルの
national-parks-demo
を使います。

Curl

filter_curl.sh
HOST="https://mar29-project.ent.asia-northeast1.gcp.cloud.es.io"
SEARCH_KEY="search-******"
NAME_ENGINE="national-parks-demo"
#
#
curl -X POST ${HOST}'/api/as/v1/engines/'$NAME_ENGINE'/search' \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer '${SEARCH_KEY} \
-d '{
  "query": "",
  "filters" : {
"states": [ "Texas", "Minnesota" ]
  }
}'
go_curl.sh
./filter_curl.sh > out01.json
jq .results[].states out01.json

実行結果

$ ./go_curl.sh 
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  2646  100  2573  100    73   5105    144 --:--:-- --:--:-- --:--:--  5302
{
  "raw": [
    "Texas"
  ]
}
{
  "raw": [
    "Minnesota"
  ]
}
{
  "raw": [
    "Texas"
  ]
}

Httpie

filter_http.sh
HOST="https://mar29-project.ent.asia-northeast1.gcp.cloud.es.io"
SEARCH_KEY="search-******"
NAME_ENGINE="national-parks-demo"
#
#
http ${HOST}'/api/as/v1/engines/'$NAME_ENGINE'/search' \
	'Authorization: Bearer '${SEARCH_KEY} < query01.json
query01.json
{
  "query": "",
  "filters" : { "states": [ "Texas", "Minnesota" ] }
}
go_http.sh
./filter_http.sh > out02.json
jq .results[].states out02.json

実行結果

$ ./go_http.sh 
{
  "raw": [
    "Texas"
  ]
}
{
  "raw": [
    "Minnesota"
  ]
}
{
  "raw": [
    "Texas"
  ]
}
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?