LoginSignup
8

More than 5 years have passed since last update.

Elasticsearchへのデータ投入と検索の方法(初級)

Posted at

前提:Elasticsearchがインストールされており、起動中であること。

データ投入(ためしに3件入れてみる)

curl -XPUT http://localhost:9200/blog/article/1 -d '
{
    "title": "My Name Is Yamato",
    "content": "I love dog",
    "tags": ["red", "green", "blue"]
}
'

curl -XPUT http://localhost:9200/blog/article/2 -d '
{
    "title": "My Name Is Tanaka",
    "content": "I love cat",
    "tags": ["Earth", "Moon", "Mars"]
}
'

curl -XPUT http://localhost:9200/blog/article/3 -d '
{
    "title": "My Name Is Watanabe",
    "content": "I love fish",
    "tags": ["apple", "orange", "banana"]
}
'

検索

curl -XGET http://localhost:9200/_search?q=title:yamato
curl -XGET http://localhost:9200/_search?q=title:tanaka
curl -XGET http://localhost:9200/_search?q=title:watanabe
curl -XGET http://localhost:9200/_search?q=content:dog
curl -XGET http://localhost:9200/_search?q=content:cat
curl -XGET http://localhost:9200/_search?q=content:fish
curl -XGET http://localhost:9200/_search?q=tags:green
curl -XGET http://localhost:9200/_search?q=tags:mars
curl -XGET http://localhost:9200/_search?q=tags:apple
curl -XGET http://localhost:9200/_search?q=tags:apple,moon

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
8