こちらで作成したデータに Ruby で問い合わせをします。
Elasticsearch へのデータ投入
Arch Linux でのライブラリーのインストール
yay -S ruby-rest-client
elastic_query.rb
#! /usr/bin/ruby
# -*- coding: utf-8 -*-
#
# elastic_search.rb
#
# Oct/04/2018
#
# ---------------------------------------------------------------------
require 'restclient'
require 'json'
#
# ---------------------------------------------------------------------
STDERR.puts "*** 開始 ***"
URL = "http://localhost:9200/_search?q=tags:apple,moon"
str_json = RestClient.get URL
dict_aa = JSON.parse(str_json)
list_aa = dict_aa['hits']['hits']
list_aa.each {|unit|
puts unit['_id']
ss = unit['_source']
puts "\t" + ss['name']
puts "\t" + ss['title']
puts "\t" + ss['content']
str_out = ""
ss['tags'].each {|tag|
str_out += "\t" + tag
}
puts str_out
}
STDERR.puts "*** 終了 ***"
# ---------------------------------------------------------------------
#
実行結果
$ ./elastic_query.rb
*** 開始 ***
t0003
渡辺五郎
My Name Is Watanabe
I love fish
apple orange banana
t0002
田中康夫
My Name Is Tanaka
I love cat
Earth Moon Mars
*** 終了 ***