スクリーンショット_2019-01-28_22

elasticsearchで記事をまとめ上げ

elasticsearchでは類似記事のまとめあげ・クラスタリングはやってくれないので、API layerでやるかプラグインを利用するしかない。pluginで公式のissueなどで紹介されてるものとしてcarrot2のESバンドルがある。carrot2は複数のクラスタリングアルゴリズム(lingo,kmeansなど)をサポートするクラスタリングエンジンで、ESのプラグインとしても開発されている。(公式ドキュメントはこちら)以下はDocker上でelasticsearch6.4.3でpluginをインストールし試して見た備忘録である. 

1. Dockerfileとelasticsearch.ymlを設定

2.  dockerでESをインストールする

docker build -t elasticsearch-carrot2:6.4.3 .

3. dockerを立ち上げる

docker run --name es6.4-carrot -p 9200:9200 -p 9300:9300 <image id>

 http://localhost:9200/

にアクセスして、正しくresponseが返却されてるかを確認する

4. carrot2のページにアクセスしてsample documentをindex

https://cdn.rawgit.com/carrot2/elasticsearch-carrot2/master/doc/index.html

Index sampleのボタンを押すとindexが始まる。visualizeを押すとこれが出てくれば終わり.

5. curl経由で叩いて見る

sample query

http://localhost:9200/test/_search_with_clusters?q=data%20mining&pretty&size=100&field_mapping_title=_source.title&field_mapping_content=_source.content

クラスター部分のresponse( documentsの要素がesの_id)


 {
  "took" : 25,
  "timed_out" : false,
  "_shards" : {
    "total" : 5,
    "successful" : 5,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : 93,
    "max_score" : 6.427984,
    "hits" : [
      {
        "_index" : "test",
        "_type" : "test",
        "_id" : "3",
        "_score" : 6.427984,
        "_source" : {
          "lang" : "en",
          "url" : "http://en.wikipedia.org/wiki/Data-mining",
          "title" : "Data mining - Wikipedia, the free encyclopedia",
          "content" : "Data mining is considered a subfield within the Computer Science field of knowledge discovery. ... claim to perform \"data mining\" by automating the creation ..."
        }
      },
      ....
        ]
  },
 "clusters" : [
    {
      "id" : 0,
      "score" : 72.85477017591413,
      "label" : "Knowledge Discovery",
      "phrases" : [
        "Knowledge Discovery"
      ],
      "documents" : [
        "3",
        "5",
        "2",
        "4",
        "9",
        "61",
        "43",
        "39",
        "34",
        "17",
        "25",
        "62",
        "74"
      ]
    },
    ...
    ]

この記事が気に入ったらサポートをしてみませんか?