solr6 の紹介(第18回 solr勉強会 資料) (2016年6月10日)

23
SOLR 6 ののの 2016 の 6 の 10 の の 18 の Solr ののの

Upload: issei-nishigata

Post on 10-Jan-2017

574 views

Category:

Technology


14 download

TRANSCRIPT

Page 1: Solr6 の紹介(第18回 Solr勉強会 資料) (2016年6月10日)

SOLR 6 の紹介2016 年 6 月 10 日第 18 回 Solr 勉強会

Page 2: Solr6 の紹介(第18回 Solr勉強会 資料) (2016年6月10日)

自己紹介➤ 株式会社ロンウイット

➤ 西潟 一生➤ コンサルタント

➤ Apache Solr, Apache ManifoldCF➤ コンサルティング➤ 技術サポート➤ トレーニング講師

などに従事

Page 3: Solr6 の紹介(第18回 Solr勉強会 資料) (2016年6月10日)

アジェンダ➤ Solr 5 からの変更点について

➤ サポートされる Java のバージョン➤ インデックスの互換性➤ スキーマの変更方法➤ スコア計算方法➤ レプリカ & シャードの削除コマンドの仕様変更➤ facet.date.* の仕様変更

➤ Solr 6 の新機能について➤ Parallel SQL➤ Streaming Expressions➤ Cross Data Center Replication➤ Graph Query Parser

など

Page 4: Solr6 の紹介(第18回 Solr勉強会 資料) (2016年6月10日)

Solr 5 からの変更点

Page 5: Solr6 の紹介(第18回 Solr勉強会 資料) (2016年6月10日)

Java 8 is required➤ Java 8 以上が必須

➤ SolrJ クライアントライブラリも含む

Page 6: Solr6 の紹介(第18回 Solr勉強会 資料) (2016年6月10日)

Index Format Changes➤ Solr 4 系 以前のインデックスとは非互換

➤ 4 系 のインデックスを 利用したい場合は Solr 5.5 に含まれる           Lucene IndexUpgrader を使用すること➤ Solr 6 から Solr 4 系 インデックスを直接読めるようになるかも?

➤ https://issues.apache.org/jira/browse/SOLR-9051

Page 7: Solr6 の紹介(第18回 Solr勉強会 資料) (2016年6月10日)

Managed Schema is now the Default➤ Managed Schema がデフォルト

➤ schema.xml は使わない.スキーマ設定は Schema API を使う.➤ 従来通り schema.xml を使う場合は solrconfig.xml に以下を記述

<schemaFactory class=“ClassicIndexSchemaFactory”/>

➤ schema.xml から Managed Schema への移行は簡単➤ conf 内の managed-schema ファイルを削除し,作成済み schema.xml を conf に配置後, Solr 起動

➤ 以下の記述が入った managed-schema ファイルが新たに作成され,配置した schema.xml は schema.xml.bak にリネームされる

    <!-- Solr managed schema - automatically generated - DO NOT EDIT -->

Page 8: Solr6 の紹介(第18回 Solr勉強会 資料) (2016年6月10日)

Managed Schema is now the Default (Example)➤ 追加curl -X POST -H 'Content-type:application/json' --data-binary '{ "add-field-type":{ "name":"myNewTxtField", "class":"solr.TextField", "positionIncrementGap":"100", "analyzer":{ "charFilters":[{ "class":"solr.PatternReplaceCharFilterFactory", "replacement":"$1$1", "pattern":"([a-zA-Z])\\\\1+" }], "tokenizer":{ "class":"solr.WhitespaceTokenizerFactory" }, "filters":[{ "class":"solr.WordDelimiterFilterFactory", "preserveOriginal":"0" }]}}, "add-field" : { "name":"sell-by", "type":"myNewTxtField", "stored":true }}' http://localhost:8983/solr/gettingstarted/schema

➤ 削除curl -X POST -H 'Content-type:application/json' --data-binary '{ "delete-field-type":{ "name":"myNewTxtField" }}' http://localhost:8983/solr/gettingstarted/schema

Page 9: Solr6 の紹介(第18回 Solr勉強会 資料) (2016年6月10日)

Default Similarity Changes➤ デフォルトのスコアの計算方法が TF/IDF から Okapi BM25 に変更

➤ 検索結果のランキング精度が改善➤ 参考資料

➤ https://www.elastic.co/blog/found-bm-vs-lucene-default-similarity

Page 10: Solr6 の紹介(第18回 Solr勉強会 資料) (2016年6月10日)

Replica & Shard Delete Command Changes➤ “DELETESHARD”, “DELETEREPLICA” コマンドで,以下のディレクトリがデフォルトで削除

➤ Instance ディレクトリ➤ Data ディレクトリ➤ Index ディレクトリ

➤ 削除したくない場合は以下のようなパラメータを false にする➤ deleteInstanceDir➤ deleteDataDir➤ deleteIndex

➤ 例    http://localhost:8983/solr/admin/collections?

action=DELETEREPLICA&collection=test2&shard=shard2&replica=core_node3&deleteInstanceDir=false

Page 11: Solr6 の紹介(第18回 Solr勉強会 資料) (2016年6月10日)

facet.data.* Parameters Removed➤ Solr 3 系 で deprecated となった facet.date パラメータが完全に削除

➤ facet.range で代用可

Page 12: Solr6 の紹介(第18回 Solr勉強会 資料) (2016年6月10日)

Doc Values➤ 非テキスト系フィールドで, DocValues がデフォルトで有効

➤ メモリ節約,ディスクサイズ増➤ 後述する Parallel SQL を使う時は DocValues を有効にしておくこと➤ 参考資料

➤ http://blog.johtani.info/blog/2014/10/02/elasticsearch-1-4-0-beta-released-ja/

➤ https://lucidworks.com/blog/2013/04/02/fun-with-docvalues-in-solr-4-2/

Page 13: Solr6 の紹介(第18回 Solr勉強会 資料) (2016年6月10日)

SOLR 6 の新機能

Page 14: Solr6 の紹介(第18回 Solr勉強会 資料) (2016年6月10日)

Parallel SQL➤ Solr で SQL が使用可能に

➤ 現在は Solr Cloud でのみ使用可

Page 15: Solr6 の紹介(第18回 Solr勉強会 資料) (2016年6月10日)

Example➤ HTTPcurl --data-urlencode 'stmt=SELECT fieldA, count(*) FROM collection1 GROUP BY fieldA ORDER BY count(*) DESC LIMIT 10'

http://localhost:8983/solr/collection1/sql?aggregationMode=facet

➤ JDBCConnection con = null;try { con = DriverManager.getConnection("jdbc:solr://" + zkHost + "?collection=collection1&aggregationMode=facet"); stmt = con.createStatement(); rs = stmt.executeQuery("SELECT fieldA, count(*) FROM collection1 GROUP BY fieldA ORDER BY count(*) DESC LIMIT 10"); while(rs.next()) { String a_s = rs.getString("fieldA"); }} finally { rs.close(); stmt.close(); con.close();}

Page 16: Solr6 の紹介(第18回 Solr勉強会 資料) (2016年6月10日)

Parallel SQL Specs➤ テーブル名 = コレクション名➤ 大小文字無視 (case insensitive)➤ サポートされる句

➤ WHERE➤ ORDER BY➤ LIMIT➤ DISTINCT

➤ GROUP BY➤ WHERE 句は Solr のシンタックス適用可

➤ OR 検索WHERE fieldA = ‘term1 term2’ → term1 OR term2 ※ デフォルトオペレーターが OR の場合

➤ 範囲検索WHERE fieldB = ‘[0 TO 100]’

➤ JDBC Driver または HTTP でリクエスト可

Page 17: Solr6 の紹介(第18回 Solr勉強会 資料) (2016年6月10日)

Limitations, etc➤ Solr Cloud のみで使用可➤ delete, insert, update 非対応➤ select されるフィールドは docValues=true 必須➤ フィールドの異なり数が多い場合は aggregationMode=map_reduce が高速      

   そうでない場合は aggregationMode=facet が高速➤ map_reduce を指定する例

curl --data-urlencode 'stmt=SELECT fieldA FROM collection1 GROUP BY fieldA LIMIT 10' http://localhost:8983/solr/collection1/sql?aggregationMode=map_reduce

Page 18: Solr6 の紹介(第18回 Solr勉強会 資料) (2016年6月10日)

Streaming Expressions➤ 並列実行されたタスクが結合可能

➤ 現在は Solr Cloud でのみ使用可➤ まだ experimental

➤ Source Stream➤ search➤ jdbc➤ facet➤ stats➤ topic

➤ Stream Decorators➤ complement➤ daemon➤ innerJoin➤ intersect➤ hashJoin➤ merge➤ leftOuterJoin➤ outerHashJoin➤ parallel➤ reduce➤ rollup➤ select➤ top➤ unique➤ update

Page 19: Solr6 の紹介(第18回 Solr勉強会 資料) (2016年6月10日)

Streaming Expressions(Example)➤ 異なるコレクションの検索結果マージ例 (exampleDocs の books.json と hd.xml がインデキシング済み )curl --data-urlencode 'expr=merge (search(gettingstarted,q="*:*",fl="id,name",sort="id asc",qt="/export"), search(gettingstarted2,q="*:*",fl="id,name",sort="id asc",qt="/export"), on="id asc")' ‘localhost:8983/solr/gettingstarted/stream’…{"result-set":{"docs":[{"name":["Maxtor DiamondMax 11 - hard drive - 500 GB - SATA-300"],"id":"6H500F0"},{"name":["The Lightning Thief"],"id":"978-0641723445"},{"name":["The Sea of Monsters"],"id":"978-1423103349"},{"name":["Sophie's World : The Greek Philosophers"],"id":"978-1857995879"},{"name":["Lucene in Action, Second Edition"],"id":"978-1933988177"},{"name":["Samsung SpinPoint P120 SP2514N - hard drive - 250 GB - ATA-133"],"id":"SP2514N"},{"EOF":true,"RESPONSE_TIME":17}]}}

Page 20: Solr6 の紹介(第18回 Solr勉強会 資料) (2016年6月10日)

Cross Data Center Replication➤ データセンターを跨いだレプリケーションをサポート

➤ まだ experimental

➤ active/passive モードで動作➤ レプリケーションは,「元」から「先」への一方

通行➤ 「先」が変更されても「元」への反映はない

➤ 「先」は結果整合性をサポート

Page 21: Solr6 の紹介(第18回 Solr勉強会 資料) (2016年6月10日)

Graph Query Parser➤ Solr のドキュメントの関係性をツリー構造で表現でき,検索が可能に

➤ 以下のようなユースケースが考えられる➤ アクセスコントロール

➤ ドキュメントに紐付いているユーザーをトラバース➤ シソーラス辞書の構築

➤ 後述

Page 22: Solr6 の紹介(第18回 Solr勉強会 資料) (2016年6月10日)

Graph Query Parser(Example)➤ 登録

curl -H 'Content-Type: application/json' 'http://localhost:8983/solr/my_graph/update?commit=true' --data-binary '[

{"id":"A","foo": 7, "out_edge":["1","9"], "in_edge":["4","2"] }, {"id":"B","foo": 12, "out_edge":["3","6"], "in_edge":["1"] }, {"id":"C","foo": 10, "out_edge":["5","9"], "in_edge":["2"] }, {"id":"D","foo": 20, "out_edge":["4","7"], "in_edge":["3","5"] }, {"id":"E","foo": 17, "out_edge":[], "in_edge":["6"] }, {"id":"F","foo": 11, "out_edge":[], "in_edge":["7"] }, {"id":"G","foo": 7, "out_edge":["8"], "in_edge":[] }, {"id":"H","foo": 10, "out_edge":[], "in_edge":["8"] }]’

➤ 検索http://localhost:8983/solr/my_graph/query?fl=id&q={!

graph+from=in_edge+to=out_edge}id:A..."response":{"numFound":6,"start":0,"docs":[ { "id":"A" }, { "id":"B" }, { "id":"C" }, { "id":"D" }, { "id":"E" }, { "id":"F" } ]}

Page 23: Solr6 の紹介(第18回 Solr勉強会 資料) (2016年6月10日)

Graph Query Parser(Example)➤ 登録

curl -H 'Content-Type: application/json' 'http://localhost:8983/solr/my_graph/update?commit=true' --data-binary '[

{"id":"A","name": 果物 , "out_edge":["1","2","3"], "in_edge":[] }, {"id":"B","name": りんご , "out_edge":[], "in_edge":["1"] }, {"id":"C","name": みかん , "out_edge":[], "in_edge":["2"] }, {"id":"D","name": ぶどう , "out_edge":[], "in_edge":["3"] }, {"id":"E","name": 野菜 , "out_edge":["4","5"], "in_edge":[] }, {"id":"F","name": いちご , "out_edge":[], "in_edge":["4"] }, {"id":"G","name": スイカ , "out_edge":[], "in_edge":["5"] }, {"id":"H","name": 米 , "out_edge":[], "in_edge":[] }

➤ 検索http://localhost:8983/solr/my_graph/query?fl=name&q={!graph from=in_edge to=out_edge

returnRoot=false}name: 果物..."response":{"numFound":3,"start":0,"docs":[ { "name":" いちご " }, { "name":" ぶどう " }, { "name":" りんご " },]}

果物

みかん ぶどう りんご

野菜

いちご スイカ