Workplace Searchの検索を試す

前回、インストールしたものの、クロール対象を用意しないとクロールできなかったので、今回はクロール対象の中で、簡単に準備できそうなDropboxをクロール対象にして試してみた。

DropboxのOAuthの設定が必要だが、手順自体はここにあるので、そこでApp KeyとApp Secretが生成できるので、それをWorkplace SearchのDropboxの接続情報に入れてConnectするとこんな感じで、取得したドキュメント件数が表示される。

今回は、Fessで使っているテスト用ファイルがfess-testdataにあるので、そこのファイルたちをDropboxに置いておいた。

とりあえず、今回は63ファイルがインデックスされたようなので、検索してみる。Go to Search Applicationで検索画面が表示される。

テスト用のファイルには「Lorem ipsum. (ロレム・イプサム) 吾輩は猫である。」という文字列があるので、試しに猫で検索してみると、こんな感じになる。

テキスト、HTML、MS Office、PDFあたりが検索できるようだ。ただ、Fessのテストデータにはいろんな種類のファイルが含まれているのですが、XMLファイルやzipに含まれるファイルなどはヒットしていなかった。あとは、仕方がない感はあるけど、Docuworks、AutoCAD,一太郎はヒットしていない。

検索結果をクリックすると、右側に情報が出てきた。それをさらにクリックすると対象のファイルに飛んでいく感じ。今回であれば、Dropboxのサイトに移動する。

絞り込みやソートについては、時間で絞り込み、関連度順と日付順のソートがある感じだった。

という感じで、今どきのUIだなという感じの印象でした。最近、Fessも今どきのUIが必要だなとは考えていたので、考えないとなと…。

Workplace Searchを試してみる

Fessを作っていると、当然ながら、他の全文検索システムも気になります 🙂

というわけで、elastic社が作っているエンタープライズサーチのWorkplace Searchも試せるようなので試してみることにします。

インストール手順はここにあるようなので、その手順に沿って、試してみます。Docker見たいのはないようなので、Ubuntuにzipのやつをコマンド叩きながら入れてみます。(コピペしていけば起動までいけるような感じでまとめるので、細かいことはドキュメントを見るのが良いです…)

まずは、適当なディレクトリでelasticsearchをダウンロードして起動。

$ wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.7.0-linux-x86_64.tar.gz
$ tar zxvf elasticsearch-7.7.0-linux-x86_64.tar.gz
$ cd elasticsearch-7.7.0/
$ echo "xpack.security.enabled: true" >> config/elasticsearch.yml
$ ./bin/elasticsearch

という感じで、elasticsearchが起動します。elasticsearchにユーザーとか作る必要があるので、別のターミナルを開いて、elasticsearchのディレクトリに行き、

$ ./bin/elasticsearch-setup-passwords auto
Initiating the setup of passwords for reserved users elastic,apm_system,kibana,logstash_system,beats_system,remote_monitoring_user.
The passwords will be randomly generated and printed to the console.
Please confirm that you would like to continue [y/N]y

Changed password for user apm_system
PASSWORD apm_system = ...略...

Changed password for user kibana
PASSWORD kibana = ...略...

Changed password for user logstash_system
PASSWORD logstash_system = ...略...

Changed password for user beats_system
PASSWORD beats_system = ...略...

Changed password for user remote_monitoring_user
PASSWORD remote_monitoring_user = ...略...

Changed password for user elastic
PASSWORD elastic = ...今回使うのはこれ...

という感じで、elasticユーザーとパスワードができます。次はWorkplace Searchをダウンロードして、設定して、起動します。

$ cd ..
$ wget https://artifacts.elastic.co/downloads/enterprise-search/enterprise-search-7.7.0.tar.gz
$ tar zxvf enterprise-search-7.7.0.tar.gz
$ cd enterprise-search-7.7.0/
$ echo "ent_search.auth.source: standard" >> config/enterprise-search.yml
$ echo "elasticsearch.username: elastic" >> config/enterprise-search.yml
$ echo "elasticsearch.password: さっきのパスワード" >> config/enterprise-search.yml
$ echo "allow_es_settings_modification: true" >> config/enterprise-search.yml
$ echo "secret_management.encryption_keys: ["`openssl rand -hex 32`", "`openssl rand -hex 32`"]" >> config/enterprise-search.yml
$ ENT_SEARCH_DEFAULT_PASSWORD=passwordexample bin/enterprise-search

とすると、しばらくすると起動が完了します。あとは、http://localhost:3002/にアクセスします。

Welcomeページが表示されます。Continue to Loginをクリックすると、ログイン画面が表示されます。

enterprise_searchユーザーで、起動時に指定したpasswordexampleをパスワードとしてログインできます。

という感じで表示されるので、Start a Free Trialを選ぶと、管理ページが表示されます。今どきのきれいなデザインですね。

検索対象に関しては、ソースを選んで登録するっぽいです。

その他にはグループやユーザー管理があります。

その他には設定関係とか。

あとは、今回、クロールする対象の準備ができなかったので、確認できてないですが、ソースの設定はこんな感じ。

という感じでした。

今回、クロールする対象が限られているので、準備して望まないと検索結果のところまで確認できなかったので、次回試すときには何かのソースを用意して検索までいきたいと思います。

で、話を戻して、Fessと比べると、Fessはもっと大きなところを対象にしていますが、エンタープライズサーチ観点ではかぶる領域もあるかと思います。クロール対象もFessでいうと、fess-ds-*のデータストアクロールとの比較になりますが、同じようなソースが存在している感じですね。ただ、Workplace Searchの方が設定画面がシンプルなので、この点は見習うべきところかもしれません…(まぁ、UI全般かもしれないけど)。

ということで、次回は検索側を確認したいと思います。

kindでelasticsearchを動かす

Kubernetes IN Docker(kind)を使えば、helmとかで簡単にk8sにelasticsearchを動かせるかなと思い、試してみる。

elasticsearchのhelmチャートはhelm/stableとelasticの2種類あるが、現時点ではelasticの方は動かなかった…。elasticの方にはexamplesにはkindの例があるのだが、これもダメなので、がんばって調べないと動かせなそうなので、一旦、これは見送って、素直にhelm/stableを試す。

kindやhelmなどの必要なものは入れてある前提で、まずは、kindでk8sのクラスタを作成する。

$ kind create cluster 
 Creating cluster "kind" …
  ✓ Ensuring node image (kindest/node:v1.15.3) 🖼
  ✓ Preparing nodes 📦 
  ✓ Creating kubeadm config 📜 
  ✓ Starting control-plane 🕹️ 
  ✓ Installing CNI 🔌 
  ✓ Installing StorageClass 💾 
 Cluster creation complete. You can now use the cluster with:

 export KUBECONFIG="$(kind get kubeconfig-path --name="kind")"
 kubectl cluster-info

という感じでクラスタが簡単にできる。kindでいろいろな設定でクラスタを作ることもできるらしい。何も指定しなければ、kindという名前のクラスタができる。

$ export KUBECONFIG="$(kind get kubeconfig-path --name="kind")"
$ kubectl cluster-info
 Kubernetes master is running at https://127.0.0.1:36777
 KubeDNS is running at https://127.0.0.1:36777/api/v1/namespaces/kube-system/services/kube-dns:dns/proxy

 To further debug and diagnose cluster problems, use 'kubectl cluster-info dump'.

KUBECONIGを設定すれば、kubectlコマンドが利用できる。あとはhelmを使うので、tillerに権限を付けて初期化しておく。

$ kubectl -n kube-system create serviceaccount tiller
 serviceaccount/tiller created
$ kubectl create clusterrolebinding tiller --clusterrole cluster-admin --serviceaccount=kube-system:tiller
 clusterrolebinding.rbac.authorization.k8s.io/tiller created
$ helm init --service-account=tiller --wait
 $HELM_HOME has been configured at /home/shinsuke/.helm.

 Tiller (the Helm server-side component) has been installed into your Kubernetes Cluster.

 Please note: by default, Tiller is deployed with an insecure 'allow unauthenticated users' policy.
 To prevent this, run helm init with the --tiller-tls-verify flag.
 For more information on securing your installation see: https://docs.helm.sh/using_helm/#securing-your-helm-installation

これ以降は普通にhelmでインストールすれば良い。

$ helm install --name my-release stable/elasticsearch
...
 From outside the cluster, run these commands in the same shell:

 export POD_NAME=$(kubectl get pods --namespace default -l "app=elasticsearch,component=client,release=my-release" -o jsonpath="{.items[0].metadata.name}")
 echo "Visit http://127.0.0.1:9200 to use Elasticsearch"
 kubectl port-forward --namespace default $POD_NAME 9200:9200 

という感じで、上記にあるようにkubectl port-forwardを実行すれば、localhost:9200でアクセスして確認することができる。

k8sのクラスタを破棄するには

$ kind delete cluster

とすれば削除できる。