0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Searchkickでのデバッグ術

Posted at

Railsコンソールでdubug: true属性?を付与して検索を実行してやると、そのときに使われた Search Option, Setting, Mapping, Results(検索スコアとか)を見れていい。

Searchkick Dubug

.rb
> Post.search "日本の絶景", fields: [:name, :description, :category_name], operator: "or", debug: true
Model Searchkick Options
{:language=>"japanese",
 :_type=>
  #<Proc:0x00007f96bd9f4858 /Users/takuya/.rbenv/versions/2.7.1/lib/ruby/gems/2.7.0/gems/searchkick-4.4.1/lib/searchkick/model.rb:17 (lambda)>,
 :class_name=>"Post"}

Search Options
{:fields=>[:name, :description, :category_name], :operator=>"or", :debug=>true}

Elasticsearch Query
curl http://localhost:9200/posts_development/_search?pretty -H 'Content-Type: application/json' -d '{"query":{"bool":{"should":[{"dis_max":{"queries":[{"match":{"name.analyzed":{"query":"日本の絶景","boost":10,"operator":"or","analyzer":"searchkick_search"}}},{"match":{"name.analyzed":{"query":"日本の絶景","boost":1,"operator":"or","analyzer":"searchkick_search","fuzziness":1,"prefix_length":0,"max_expansions":3,"fuzzy_transpositions":true}}}]}},{"dis_max":{"queries":[{"match":{"description.analyzed":{"query":"日本の絶景","boost":10,"operator":"or","analyzer":"searchkick_search"}}},{"match":{"description.analyzed":{"query":"日本の絶景","boost":1,"operator":"or","analyzer":"searchkick_search","fuzziness":1,"prefix_length":0,"max_expansions":3,"fuzzy_transpositions":true}}}]}},{"dis_max":{"queries":[{"match":{"category_name.analyzed":{"query":"日本の絶景","boost":10,"operator":"or","analyzer":"searchkick_search"}}},{"match":{"category_name.analyzed":{"query":"日本の絶景","boost":1,"operator":"or","analyzer":"searchkick_search","fuzziness":1,"prefix_length":0,"max_expansions":3,"fuzzy_transpositions":true}}}]}}]}},"timeout":"11s","_source":false,"size":10000}'

Elasticsearch Results
{
  "took": 10,
  "timed_out": false,
  "_shards": {
    "total": 1,
    "successful": 1,
    "skipped": 0,
    "failed": 0
  },
  "hits": {
    "total": {
      "value": 21,
      "relation": "eq"
    },
    "max_score": 57.485226,
    "hits": [
      {
        "_index": "posts_development_20200709213129463",
        "_type": "_doc",
        "_id": "28",
        "_score": 57.485226
      },
      {
        "_index": "posts_development_20200709213129463",
        "_type": "_doc",
        "_id": "20",
        "_score": 46.743748
      }
    ]
  }
}
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?