LoginSignup
1
1

More than 5 years have passed since last update.

ElasticSearchコマンドメモ

Posted at

絶対忘れるので使ったコマンドを書いておく。

ElasticSearch 5.5で確認

インデックスを確認

curl -XGET localhost:9200/_cat/indices

指定したフィールドを取得

curl -XGET 'http://localhost:9200/(インデックス名)/_search?pretty' -d '
{
  "_source": [ "(取得するフィールド名1)", "(取得するフィールド名2)"]
}'

指定フィールドから指定文字列を検索

curl -XGET 'http://localhost:9200/(インデックス名)/_search?pretty' -d '
{
  "_source": [ "(取得するフィールド名1)", "(取得するフィールド名2)"],
  "query":{
    "match":{
      "(検索フィールド名)": {
        "query": "(検索文字列)",
        "type": "phrase"
      }
    }
  }
}'

指定フィールドから指定文字列を検索 (AND検索)

curl -XGET 'http://localhost:9200/(インデックス名)/_search?pretty' -d '
{
  "_source": [ "(取得するフィールド名1)", "(取得するフィールド名2)"],
  "query":{
    "bool":{
      "must": [
      {
        "match":{
          "(検索フィールド名)": {
            "query": "(検索文字列)",
            "type": "phrase"
          }
        }
      },
      {
        "match":{
          "(検索フィールド名)": {
            "query": "(検索文字列)",
            "type": "phrase"
          }
        }
      }
      ]
    }
  }
}'

指定フィールドから指定文字列を検索 (OR検索)

curl -XGET 'http://localhost:9200/(インデックス名)/_search?pretty' -d '
{
  "_source": [ "(取得するフィールド名1)", "(取得するフィールド名2)"],
  "query":{
    "bool":{
      "should": [
      {
        "match":{
          "(検索フィールド名)": {
            "query": "(検索文字列)",
            "type": "phrase"
          }
        }
      },
      {
        "match":{
          "(検索フィールド名)": {
            "query": "(検索文字列)",
            "type": "phrase"
          }
        }
      }
      ]
    }
  }
}'
1
1
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
1
1