Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
7
Help us understand the problem. What is going on with this article?
@wakanayoshizawa

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

7
Help us understand the problem. What is going on with this article?
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.
Sign Up
If you already have a Qiita account Login
7
Help us understand the problem. What is going on with this article?