さて、前回に続きようやく Elasticsearch での、データの検索機能を試してみます。
★関連記事
Elasticsearch 6 を使ったデータ検証 その1(Dockerでコンテナの作成と確認)
Elasticsearch 6 を使ったデータ検証 その2(マッピングの登録をしてみる)
Elasticsearch 6 を使ったデータ検証 その3(bulkでデータを投入してみる)
Elasticsearch 6 を使ったデータ検証 その5(クエリでの検索)
Elasticsearch 6 を使ったデータ検証 その6(Aggregationを使った分類・集計)
Elasticsearch 6 を使ったデータ検証 その7(Analyzerについて)
今回のデータ投入などは以下のサイトを参考にしながらバージョンでの違いなどの確認を行っています。
★Elasticsearchチュートリアル
http://code46.hatenablog.com/entry/2014/01/21/115620
こちらの検索との違いの比較を目的として今回の検索を実施します。
元々のサイトでのゴールは以下となっています。
【レストラン検索のゴール】
- 「地名 料理ジャンル/店名」と言った形でレストランが探せる
- メニュー名からレストランが探せる(例えば「ハンバーガー」が美味しいお店)
- PV順・口コミが多い順・評価が高い順など検索結果をソートできる
「地名 料理ジャンル/店名」と言った形でレストランを探す
さて、最初に「simple_query_string」というqueryを使っての検索です。
同じ検索を以下で実施で。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
$ curl -H "Content-Type: application/json" -XGET 'http://localhost:9200/restaurant/type/_search?pretty=true' -d ' > { > "query" : { > "simple_query_string" : { > "query": "目黒 とんき", > "fields": ["_all"], > "default_operator": "and" > } > } > } > ' { "took" : 28, "timed_out" : false, "_shards" : { "total" : 5, "successful" : 5, "skipped" : 0, "failed" : 0 }, "hits" : { "total" : 0, "max_score" : null, "hits" : [ ] } } |
はい。Elasticsearch6から「_all」のfieldsは利用できないのでいきなりhitsが0でした。
次に任意のフィールドを指定した検索。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
$ curl -H "Content-Type: application/json" -XGET 'http://localhost:9200/restaurant/type/_search?pretty=true' -d ' > { > "query" : { > "simple_query_string" : { > "query": "白金台 カフェ ボエム", > "fields": ["name", "name_kana", "address"], > "default_operator": "and" > } > } > } > ' { "took" : 365, "timed_out" : false, "_shards" : { "total" : 5, "successful" : 5, "skipped" : 0, "failed" : 0 }, "hits" : { "total" : 1, "max_score" : 23.290314, "hits" : [ { "_index" : "restaurant", "_type" : "type", "_id" : "JmJdMmUBqTWP-DutsalS", "_score" : 23.290314, "_source" : { "photo_count" : 0, "description" : "白金台駅から徒歩約5分 (料理・営業時間・カード・禁煙欄を更新しました。 東京グルメ ユーザー自治班 2007/12/9)", "menu_count" : 0, "name_alphabet" : "cafe LA BOHEME", "purpose" : "2,5,6,8", "address" : "港区白金台4-19-17", "category" : "501 202 203 204 601", "name" : "カフェ・ラ・ボエム", "access_count" : 10727, "location" : "35.3809280,139.4334072", "closed" : "false", "name_kana" : "かふぇらぼえむ" } } ] } } |
こちらは無事同じ結果が返ってきました。
ただ、スコアを比べると、こちらが「23.290314」で元記事が「3.6026812」なので、スコアリングに大きな変化が見られますね。(Analyzerなども違うのですが)
PV順・口コミが多い順・評価が高い順など検索結果をソート
次に検索結果の並び順ソートの確認。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 |
$ curl -H "Content-Type: application/json" -XGET 'http://localhost:9200/restaurant/type/_search?pretty=true' -d ' > { > "query" : { > "simple_query_string" : { > "query": "東京 ラーメン", > "fields": ["name", "name_kana", "address"], > "default_operator": "and" > } > }, > "sort" : [{ "access_count" : {"order" : "desc", "missing" : "_last"}}] > } > ' { "took" : 93, "timed_out" : false, "_shards" : { "total" : 5, "successful" : 5, "skipped" : 0, "failed" : 0 }, "hits" : { "total" : 46, "max_score" : null, "hits" : [ { "_index" : "restaurant", "_type" : "type", "_id" : "KmNdMmUBqTWP-DutsRJX", "_score" : null, "_source" : { "photo_count" : 19, "description" : "西武池袋線 ひばりヶ丘駅南口下車 徒歩3分 2006年6月11日(日)営業開始 【註】電話番号非公開です。 (from 東京グルメ 2006/06/11) 店名修正しました(サポート 2006/06/14) ", "menu_count" : 0, "name_alphabet" : "", "purpose" : "1,4", "address" : "西東京市谷戸町3-27-24ひばりヶ丘プラザ1F", "category" : "317 320 318", "name" : "ラーメン二郎", "access_count" : 35328, "location" : "35.4448512,139.3249261", "closed" : "false", "name_kana" : "らーめんじろう" }, "sort" : [ 35328 ] }, { "_index" : "restaurant", "_type" : "type", "_id" : "b2JdMmUBqTWP-DutscdT", "_score" : null, "_source" : { "photo_count" : 3, "description" : "亀有駅から3分。北口を出て駅前ロータリーをまっすぐ行き、交差点で斜め右へ進み、街道に出たら、黄色い看板が目に入る。 古っぽいけど、入口は自動ドア。入って左側にセルフの給水器あり。 カウンターのみ12席。", "menu_count" : 0, "name_alphabet" : "", "purpose" : "4", "address" : "葛飾区亀有5-49-6", "category" : "318 319 329 315", "name" : "東京ラーメン", "access_count" : 13432, "location" : "35.4558241,139.5107848", "closed" : "true", "name_kana" : "とうきょうらーめん" }, "sort" : [ 13432 ] }, { "_index" : "restaurant", "_type" : "type", "_id" : "22JdMmUBqTWP-DutsZ9R", "_score" : null, "_source" : { "photo_count" : 2, "description" : "お台場海浜公園駅からすぐ", "menu_count" : 0, "name_alphabet" : "", "purpose" : "", "address" : "港区台場1-6-1デックス東京ビーチ6F", "category" : "332 313 317", "name" : "中国ラーメン揚州商人", "access_count" : 8919, "location" : "35.3733402,139.4644180", "closed" : "true", "name_kana" : "ちゅうごくらーめんようしゅうしょうにん" }, "sort" : [ 8919 ] }, { "_index" : "restaurant", "_type" : "type", "_id" : "M2JdMmUBqTWP-DutsZZQ", "_score" : null, "_source" : { "photo_count" : 2, "description" : "初台から山手通りを北に行き、清水橋交差点の手前100mくらいにあるローソンの横 営業時間情報、定休日情報を追加しました。 (from 東京グルメ 2007/02/04)", "menu_count" : 1, "name_alphabet" : "tokyo rahmen ten", "purpose" : "4", "address" : "渋谷区本町3丁目48-21豊栄新都心マンション1階", "category" : "317", "name" : "東京ラーメン てん", "access_count" : 7377, "location" : "35.4104272,139.4110385", "closed" : "false", "name_kana" : "とうきょうらーめんてん" }, "sort" : [ 7377 ] }, { "_index" : "restaurant", "_type" : "type", "_id" : "v2JdMmUBqTWP-DutsZlR", "_score" : null, "_source" : { "photo_count" : 5, "description" : "東京駅・八重洲中央口より徒歩3分。北一番街内", "menu_count" : 0, "name_alphabet" : "", "purpose" : "4", "address" : "中央区八重洲2-1東京名店街B1", "category" : "317 323", "name" : "旭川ラーメン番外地", "access_count" : 5715, "location" : "35.4035537,139.4622382", "closed" : "false", "name_kana" : "あさひかわらーめんばんがいち" }, "sort" : [ 5715 ] }, { "_index" : "restaurant", "_type" : "type", "_id" : "CGJdMmUBqTWP-DutsaRR", "_score" : null, "_source" : { "photo_count" : 1, "description" : "", "menu_count" : 0, "name_alphabet" : "", "purpose" : "", "address" : "目黒区上目黒1-23-7", "category" : "317", "name" : "東京ラーメン横丁", "access_count" : 5377, "location" : "35.3828079,139.4210217", "closed" : "false", "name_kana" : "とうきょうらーめんよこちょう" }, "sort" : [ 5377 ] }, { "_index" : "restaurant", "_type" : "type", "_id" : "2mJdMmUBqTWP-DutsZlR", "_score" : null, "_source" : { "photo_count" : 1, "description" : "大丸地下、東京駅地下名店街内「ラーメン激戦区」内", "menu_count" : 0, "name_alphabet" : "", "purpose" : "4", "address" : "千代田区丸の内1-9-1東京駅地下名店街", "category" : "317 332", "name" : "中国ラーメン揚州商人", "access_count" : 4006, "location" : "35.4037931,139.4617839", "closed" : "true", "name_kana" : "ちゅうごくらーめんようしゅうしょうにん" }, "sort" : [ 4006 ] }, { "_index" : "restaurant", "_type" : "type", "_id" : "9WJdMmUBqTWP-Dutsd1U", "_score" : null, "_source" : { "photo_count" : 5, "description" : "", "menu_count" : 1, "name_alphabet" : "", "purpose" : "4", "address" : "西東京市保谷町5-8-15", "category" : "317 320 318 333 319", "name" : "ラーメン 藤亭", "access_count" : 3915, "location" : "35.4342863,139.3307528", "closed" : "false", "name_kana" : "らーめんふじてい" }, "sort" : [ 3915 ] }, { "_index" : "restaurant", "_type" : "type", "_id" : "UmJdMmUBqTWP-DutsZlR", "_score" : null, "_source" : { "photo_count" : 8, "description" : "徒歩2分。ひばりヶ丘駅北口を出て右へ。道なりに進み、突き当たりを左折。 06/05/10 営業時間 URL等更新(From東京グルメ)", "menu_count" : 1, "name_alphabet" : "", "purpose" : "4", "address" : "西東京市ひばりが丘北3-2-5", "category" : "317 318 329 333", "name" : "ラーメンサニー", "access_count" : 3675, "location" : "35.4455226,139.3259392", "closed" : "false", "name_kana" : "らーめんさにー" }, "sort" : [ 3675 ] }, { "_index" : "restaurant", "_type" : "type", "_id" : "l2JdMmUBqTWP-DutsflW", "_score" : null, "_source" : { "photo_count" : 0, "description" : "近鉄四日市駅北口より徒歩2分。 「ディア四日市一番街」商店街をまっすぐ進み、「パーラーホームラン」のとなり。 【更新:[2005/10/31]】", "menu_count" : 0, "name_alphabet" : "", "purpose" : "1", "address" : "四日市市諏訪栄町4-9", "category" : "317 320 318 332", "name" : "東京おぎくぼラーメン ゑびすや", "access_count" : 3456, "location" : "34.5749417,136.3725658", "closed" : "false", "name_kana" : "とうきょうおぎくぼらーめんえびすや" }, "sort" : [ 3456 ] } ] } }こ |
これはPVで並べ替えしているので結果は同じっぽいです。
(元記事が2件しか結果表示していませんが)
ソートなのでここは違いはないでしょう。
ドキュメントのスコアを自分で定義する
この辺りからだんだんと結果が面白く。
「望ましい条件を列挙し、どれかにヒットすれば加点」という項目です。
まず、全く同じように実施します。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
$ curl -H "Content-Type: application/json" -o result.json 'http://localhost:9200/restaurant/type/_search?pretty=true' -d ' > { > "query" : { > "function_score" : { > "query" : { > "simple_query_string" : { > "query": "ハンバーガー", > "fields": ["name", "name_kana", "address"], > "default_operator": "and" > } > }, > "score_mode": "sum", > "boost_mode": "replace", > "functions" : [ > { > "filter" : { "range" : { "access_count" : { "from" : 500 }}}, > "boost_factor" : 10 > }, > { > "filter" : { "range" : { "photo_count" : { "from" : 3 }}}, > "boost_factor" : 10 > }, > { > "filter" : { "geo_distance" : { "distance" : "2km", "location" : [139.43 , 35.38] }}, > "boost_factor" : 100 > } > ] > } > } > } > ' $ cat result.json { "error" : { "root_cause" : [ { "type" : "parsing_exception", "reason" : "failed to parse [function_score] query. field [boost_factor] is not supported", "line" : 17, "col" : 28 } ], "type" : "parsing_exception", "reason" : "failed to parse [function_score] query. field [boost_factor] is not supported", "line" : 17, "col" : 28 }, "status" : 400 } |
こちらはエラーとなっています。
これはブーストの値は「boost_factor」が非推奨となり「weight」になったためです。
そこで項目を変えて再度実施。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 |
$ curl -H "Content-Type: application/json" -o result.json 'http://localhost:9200/restaurant/type/_search?pretty=true' -d ' > { > "query" : { > "function_score" : { > "query" : { > "simple_query_string" : { > "query": "ハンバーガー", > "fields": ["name", "name_kana", "address"], > "default_operator": "and" > } > }, > "score_mode": "sum", > "boost_mode": "replace", > "functions" : [ > { > "filter" : { "range" : { "access_count" : { "from" : 500 }}}, > "weight" : 10 > }, > { > "filter" : { "range" : { "photo_count" : { "from" : 3 }}}, > "weight" : 10 > }, > { > "filter" : { "geo_distance" : { "distance" : "2km", "location" : [139.43 , 35.38] }}, > "weight" : 100 > } > ] > } > } > } > ' $ cat result.json { "took" : 118, "timed_out" : false, "_shards" : { "total" : 5, "successful" : 5, "skipped" : 0, "failed" : 0 }, "hits" : { "total" : 13, "max_score" : 110.0, "hits" : [ { "_index" : "restaurant", "_type" : "type", "_id" : "6WNdMmUBqTWP-DutsUNZ", "_score" : 110.0, "_source" : { "photo_count" : 0, "description" : "", "menu_count" : 0, "name_alphabet" : "", "purpose" : "4", "address" : "港区西麻布1-11-6メンテルス六本木1F", "category" : "214", "name" : "ハンバーガーイン", "access_count" : 2846, "location" : "35.3925578,139.4340328", "closed" : "false", "name_kana" : "はんばーがーいん" } }, { "_index" : "restaurant", "_type" : "type", "_id" : "VmNdMmUBqTWP-DutsWFa", "_score" : 110.0, "_source" : { "photo_count" : 0, "description" : "店舗一時休止中", "menu_count" : 0, "name_alphabet" : "", "purpose" : "1,2,3,4", "address" : "渋谷区神宮前5-29-10", "category" : "214 614 610", "name" : "一番東京ハンバーガー", "access_count" : 1642, "location" : "35.3940140,139.4222936", "closed" : "false", "name_kana" : "いちばんとうきょうはんばーがー" } }, { "_index" : "restaurant", "_type" : "type", "_id" : "x2NdMmUBqTWP-DutsW1b", "_score" : 110.0, "_source" : { "photo_count" : 0, "description" : "", "menu_count" : 0, "name_alphabet" : "the Hamburger Inn", "purpose" : "1,2,4", "address" : "港区西麻布2-25-23バルビゾン27 3F", "category" : "214", "name" : "ザ・ハンバーガー・イン 一番東京ハンバーガー", "access_count" : 1424, "location" : "35.3923900,139.4329478", "closed" : "false", "name_kana" : "ざはんばーがーいんいちばんとうきょうはんばーがー" } }, { "_index" : "restaurant", "_type" : "type", "_id" : "32NdMmUBqTWP-Dutsdtg", "_score" : 110.0, "_source" : { "photo_count" : 0, "description" : "", "menu_count" : 0, "name_alphabet" : "", "purpose" : "4", "address" : "港区高輪4-10-18京急ショッピングプラザ ウィング高輪 WEST 1F", "category" : "214", "name" : "ハンバーガー マクドナルド", "access_count" : 1189, "location" : "35.3732189,139.4423226", "closed" : "false", "name_kana" : "はんばーがーまくどなるどうぃんぐたかなわてん" } }, { "_index" : "restaurant", "_type" : "type", "_id" : "NmJdMmUBqTWP-DutsbVS", "_score" : 110.0, "_source" : { "photo_count" : 1, "description" : "2005年10月25日で閉店されたそうです。 (from 東京グルメ 2006/11/09)", "menu_count" : 0, "name_alphabet" : "", "purpose" : "", "address" : "港区六本木3-15-22", "category" : "601 214", "name" : "ザ・ハンバーガーイン", "access_count" : 687, "location" : "35.3932299,139.4418222", "closed" : "true", "name_kana" : "ざはんばーがーいん" } }, { "_index" : "restaurant", "_type" : "type", "_id" : "kmRdMmUBqTWP-Dutsbdp", "_score" : 20.0, "_source" : { "photo_count" : 3, "description" : "16席・駐車場10台", "menu_count" : 0, "name_alphabet" : "", "purpose" : "3", "address" : "佐世保市有福町297-20", "category" : "214", "name" : "焼肉屋さんのハンバーガー あいかわ", "access_count" : 624, "location" : "33.0726051,129.4728316", "closed" : "false", "name_kana" : "やきにくやさんのはんばーがー あいかわ" } }, { "_index" : "restaurant", "_type" : "type", "_id" : "7WRdMmUBqTWP-DutsXln", "_score" : 20.0, "_source" : { "photo_count" : 11, "description" : "三軒茶屋駅より世田谷通りを西へ。りそな銀行横の脇道を入ったすぐ。三軒茶屋駅より徒歩5分程度。", "menu_count" : 0, "name_alphabet" : "", "purpose" : "1,2", "address" : "", "category" : "703 214", "name" : "グルメハンバーガーのお店 ハラカラ。", "access_count" : 988, "location" : "35.3822600,139.4014300", "closed" : "false", "name_kana" : "ぐるめはんばーがーのおみせ はらから" } }, { "_index" : "restaurant", "_type" : "type", "_id" : "8GVdMmUBqTWP-DutsYNz", "_score" : 10.0, "_source" : { "photo_count" : 0, "description" : "", "menu_count" : 0, "name_alphabet" : "THE CORNER Hamburger&Saloon", "purpose" : "1", "address" : "", "category" : "214", "name" : "ザ・コーナー ハンバーガー&サロン", "access_count" : 507, "location" : "35.1021378,136.5329184", "closed" : "false", "name_kana" : "ざこーなーはんばーがーあんどさろん" } }, { "_index" : "restaurant", "_type" : "type", "_id" : "mmRdMmUBqTWP-DutsVFl", "_score" : 10.0, "_source" : { "photo_count" : 0, "description" : "", "menu_count" : 0, "name_alphabet" : "", "purpose" : "1,4", "address" : "", "category" : "214", "name" : "ハンバーガーショップ レイダック", "access_count" : 692, "location" : "33.3855327,130.4053368", "closed" : "false", "name_kana" : "れいだっく" } }, { "_index" : "restaurant", "_type" : "type", "_id" : "O2VdMmUBqTWP-Dutsal1", "_score" : 10.0, "_source" : { "photo_count" : 14, "description" : "", "menu_count" : 0, "name_alphabet" : "", "purpose" : "1,2,4", "address" : "", "category" : "214", "name" : "アメリカンレストラン・ハンバーガーランド", "access_count" : 469, "location" : "36.0529374,136.1521308", "closed" : "false", "name_kana" : "あめりかんれすとらんはんばーがーらんど" } } ] } } |
これは結果がかなり変わりました。
そもそも元記事の方のスコアが「2232.2642」と非常に高いですが、条件にマッチしたら値が大き変わり100、10、10の加算でスコアが大きすぎるような。
こちらのデータでは最大のもので「110」となっており、元のスコアから加算された「100+10」に置き換わっています。
こちらを「replace」ではなく、「sum」に変更してみます。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 |
$ curl -H "Content-Type: application/json" -o result.json 'http://localhost:9200/restaurant/type/_search?pretty=true' -d ' > { > "query" : { > "function_score" : { > "query" : { > "simple_query_string" : { > "query": "ハンバーガー", > "fields": ["name", "name_kana", "address"], > "default_operator": "and" > } > }, > "score_mode": "sum", > "boost_mode": "sum", > "functions" : [ > { > "filter" : { "range" : { "access_count" : { "from" : 500 }}}, > "weight" : 10 > }, > { > "filter" : { "range" : { "photo_count" : { "from" : 3 }}}, > "weight" : 10 > }, > { > "filter" : { "geo_distance" : { "distance" : "2km", "location" : [139.43 , 35.38] }}, > "weight" : 100 > } > ] > } > } > } > ' $ cat result.json { "took" : 30, "timed_out" : false, "_shards" : { "total" : 5, "successful" : 5, "skipped" : 0, "failed" : 0 }, "hits" : { "total" : 13, "max_score" : 121.25328, "hits" : [ { "_index" : "restaurant", "_type" : "type", "_id" : "32NdMmUBqTWP-Dutsdtg", "_score" : 121.25328, "_source" : { "photo_count" : 0, "description" : "", "menu_count" : 0, "name_alphabet" : "", "purpose" : "4", "address" : "港区高輪4-10-18京急ショッピングプラザ ウィング高輪 WEST 1F", "category" : "214", "name" : "ハンバーガー マクドナルド", "access_count" : 1189, "location" : "35.3732189,139.4423226", "closed" : "false", "name_kana" : "はんばーがーまくどなるどうぃんぐたかなわてん" } }, { "_index" : "restaurant", "_type" : "type", "_id" : "6WNdMmUBqTWP-DutsUNZ", "_score" : 120.729034, "_source" : { "photo_count" : 0, "description" : "", "menu_count" : 0, "name_alphabet" : "", "purpose" : "4", "address" : "港区西麻布1-11-6メンテルス六本木1F", "category" : "214", "name" : "ハンバーガーイン", "access_count" : 2846, "location" : "35.3925578,139.4340328", "closed" : "false", "name_kana" : "はんばーがーいん" } }, { "_index" : "restaurant", "_type" : "type", "_id" : "VmNdMmUBqTWP-DutsWFa", "_score" : 120.710526, "_source" : { "photo_count" : 0, "description" : "店舗一時休止中", "menu_count" : 0, "name_alphabet" : "", "purpose" : "1,2,3,4", "address" : "渋谷区神宮前5-29-10", "category" : "214 614 610", "name" : "一番東京ハンバーガー", "access_count" : 1642, "location" : "35.3940140,139.4222936", "closed" : "false", "name_kana" : "いちばんとうきょうはんばーがー" } }, { "_index" : "restaurant", "_type" : "type", "_id" : "NmJdMmUBqTWP-DutsbVS", "_score" : 120.69966, "_source" : { "photo_count" : 1, "description" : "2005年10月25日で閉店されたそうです。 (from 東京グルメ 2006/11/09)", "menu_count" : 0, "name_alphabet" : "", "purpose" : "", "address" : "港区六本木3-15-22", "category" : "601 214", "name" : "ザ・ハンバーガーイン", "access_count" : 687, "location" : "35.3932299,139.4418222", "closed" : "true", "name_kana" : "ざはんばーがーいん" } }, { "_index" : "restaurant", "_type" : "type", "_id" : "x2NdMmUBqTWP-DutsW1b", "_score" : 120.567406, "_source" : { "photo_count" : 0, "description" : "", "menu_count" : 0, "name_alphabet" : "the Hamburger Inn", "purpose" : "1,2,4", "address" : "港区西麻布2-25-23バルビゾン27 3F", "category" : "214", "name" : "ザ・ハンバーガー・イン 一番東京ハンバーガー", "access_count" : 1424, "location" : "35.3923900,139.4329478", "closed" : "false", "name_kana" : "ざはんばーがーいんいちばんとうきょうはんばーがー" } }, { "_index" : "restaurant", "_type" : "type", "_id" : "kmRdMmUBqTWP-Dutsbdp", "_score" : 26.767029, "_source" : { "photo_count" : 3, "description" : "16席・駐車場10台", "menu_count" : 0, "name_alphabet" : "", "purpose" : "3", "address" : "佐世保市有福町297-20", "category" : "214", "name" : "焼肉屋さんのハンバーガー あいかわ", "access_count" : 624, "location" : "33.0726051,129.4728316", "closed" : "false", "name_kana" : "やきにくやさんのはんばーがー あいかわ" } }, { "_index" : "restaurant", "_type" : "type", "_id" : "7WRdMmUBqTWP-DutsXln", "_score" : 26.495672, "_source" : { "photo_count" : 11, "description" : "三軒茶屋駅より世田谷通りを西へ。りそな銀行横の脇道を入ったすぐ。三軒茶屋駅より徒歩5分程度。", "menu_count" : 0, "name_alphabet" : "", "purpose" : "1,2", "address" : "", "category" : "703 214", "name" : "グルメハンバーガーのお店 ハラカラ。", "access_count" : 988, "location" : "35.3822600,139.4014300", "closed" : "false", "name_kana" : "ぐるめはんばーがーのおみせ はらから" } }, { "_index" : "restaurant", "_type" : "type", "_id" : "mmRdMmUBqTWP-DutsVFl", "_score" : 19.829872, "_source" : { "photo_count" : 0, "description" : "", "menu_count" : 0, "name_alphabet" : "", "purpose" : "1,4", "address" : "", "category" : "214", "name" : "ハンバーガーショップ レイダック", "access_count" : 692, "location" : "33.3855327,130.4053368", "closed" : "false", "name_kana" : "れいだっく" } }, { "_index" : "restaurant", "_type" : "type", "_id" : "O2VdMmUBqTWP-Dutsal1", "_score" : 18.717491, "_source" : { "photo_count" : 14, "description" : "", "menu_count" : 0, "name_alphabet" : "", "purpose" : "1,2,4", "address" : "", "category" : "214", "name" : "アメリカンレストラン・ハンバーガーランド", "access_count" : 469, "location" : "36.0529374,136.1521308", "closed" : "false", "name_kana" : "あめりかんれすとらんはんばーがーらんど" } }, { "_index" : "restaurant", "_type" : "type", "_id" : "8GVdMmUBqTWP-DutsYNz", "_score" : 18.299427, "_source" : { "photo_count" : 0, "description" : "", "menu_count" : 0, "name_alphabet" : "THE CORNER Hamburger&Saloon", "purpose" : "1", "address" : "", "category" : "214", "name" : "ザ・コーナー ハンバーガー&サロン", "access_count" : 507, "location" : "35.1021378,136.5329184", "closed" : "false", "name_kana" : "ざこーなーはんばーがーあんどさろん" } } ] } } |
元のデータに定義したスコアが追加されました。
「ハンバーガー」という名前が他の文字と連続していないお店がよりスコアが高くなっています。
これは実際の検索でお店の名前にマッチ率が高ければスコアが高くなるので結果としては非常に納得がいきます。
今回は元々の記事との比較で違いなどを確認してみましたが、Elasticsearchでは非常に多くのことができるので引き続き検証を行っていきます。
★関連記事
Elasticsearch 6 を使ったデータ検証 その1(Dockerでコンテナの作成と確認)
Elasticsearch 6 を使ったデータ検証 その2(マッピングの登録をしてみる)
Elasticsearch 6 を使ったデータ検証 その3(bulkでデータを投入してみる)
Elasticsearch 6 を使ったデータ検証 その5(クエリでの検索)
Elasticsearch 6 を使ったデータ検証 その6(Aggregationを使った分類・集計)
Elasticsearch 6 を使ったデータ検証 その7(Analyzerについて)
このブログは株式会社CoLabMixによる技術ブログです。
GCP、AWSなどでのインフラ構築・運用や、クローリング・分析・検索などを主体とした開発を行なっています。
Ruby on RailsやDjango、Pythonなどの開発依頼などお気軽にお声がけください。
開発パートナーを増やしたいという企業と積極的に繋がっていきたいです。
お問い合わせやご依頼・ご相談など