Help us understand the problem. What is going on with this article?

AWS ElasticSearch ServiceのデータをPHPで取得する

More than 1 year has passed since last update.

ESデータがGETでフルオープンの場合の取得方法です。
ESのポリシーにIAM RoleのARN書きたいんじゃぁ〜って方はこちら=>IAM Roleを使ってAWS ElasticSearch ServiceのデータをLaravelで取得する

AWS側の設定

Amazon Elasticsearch Serviceポリシー例
外部からのGETのみ許可します。

{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Principal": {
        "AWS": "*"
      },
      "Action": "es:ESHttpGet",
      "Resource": "arn:aws:es:ap-northeast-1:000000000000:domain/xxx/*"
    }
  ]
}

ComposerでClientBuilderをインストール

ClientBuilderが必要なのでcomposer.jsonに追記します。

composer.json
"require": {
    "elasticsearch/elasticsearch": "~6.0"
}

$ composer update

準備が整ったのであともう一歩です。

PHP側から読み込み

xxx.php
use Elasticsearch\ClientBuilder;

$hosts = [
    'https://xxx.ap-northeast-1.es.amazonaws.com:443'
];

$client = ClientBuilder::create()->setHosts($hosts)->build();

$params = [
    'index' => '*'
];

$response = $client->search($params);

$responseにデータ返ってきていると思います。

パラメーターの詳しい書き方はこちら
https://www.elastic.co/guide/en/elasticsearch/client/php-api/current/_search_operations.html

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした