1

このページから、私はこれを試しています:

[15] pry(main)> puts Post.search("price:>600").size
  Post Search (18.7ms)  curl http://localhost:9200/posts_development/_search?pretty -d '{"query":{"dis_max":{"queries":[{"match":{"_all":{"query":"price:\u003e600","operator":"and","boost":10,"analyzer":"searchkick_search"}}},{"match":{"_all":{"query":"price:\u003e600","operator":"and","boost":10,"analyzer":"searchkick_search2"}}},{"match":{"_all":{"query":"price:\u003e600","operator":"and","boost":1,"fuzziness":1,"max_expansions":3,"analyzer":"searchkick_search"}}},{"match":{"_all":{"query":"price:\u003e600","operator":"and","boost":1,"fuzziness":1,"max_expansions":3,"analyzer":"searchkick_search2"}}}]}},"size":100000,"from":0,"fields":[]}'
0
=> nil

価格が 600 を超えるエントリがありますが、

[16] pry(main)> puts Post.where("price>600").size
   (0.2ms)  SELECT COUNT(*) FROM "posts" WHERE (price>600)
45
=> nil

これら2つの出力が異なる理由について何かアドバイスはありますか? それはおそらくスケープされたキャラクター"query":"price:\u003e600"ですか?

私も試しました:

[37] pry(main)> Post.search(where: {price: {gt: 600}}).size
  Post Search (9.8ms)  curl http://localhost:9200/posts_development/_search?pretty -d '{"query":{"match_all":{}},"size":100000,"from":0,"filter":{"and":[{"range":{"price":{"from":600,"include_lower":true}}}]},"fields":[]}'
  Post Load (0.5ms)  SELECT "posts".* FROM "posts" WHERE "posts"."id" IN (4, 9, 11, 16, 28, 35, 42, 5, 12, 17, 24, 29, 31, 36, 43, 48, 50, 1, 6, 13, 20, 25, 32, 37, 44, 2, 7, 14, 19, 21, 26, 33, 38, 40, 45, 3, 8, 10, 15, 22, 27, 34, 39, 41, 46)
=> 45

[38] pry(main)> Post.search(facets: {price: {ranges: [{from: 600}] }  }).size
  Post Search (10.4ms)  curl http://localhost:9200/posts_development/_search?pretty -d '{"query":{"match_all":{}},"size":100000,"from":0,"facets":{"price":{"range":{"price":[{"from":600}]}}},"fields":[]}'
  Post Load (0.7ms)  SELECT "posts".* FROM "posts" WHERE "posts"."id" IN (4, 9, 11, 16, 23, 28, 30, 35, 42, 47, 5, 12, 17, 24, 29, 31, 36, 43, 48, 50, 1, 6, 13, 18, 20, 25, 32, 37, 44, 49, 2, 7, 14, 19, 21, 26, 33, 38, 40, 45, 3, 8, 10, 15, 22, 27, 34, 39, 41, 46)
=> 50

where私が期待するものを作ります:45の投稿。しかし、私は理解できませんfacet。誰かがそれを手伝ってくれますか?

この質問もここにあります。

4

1 に答える 1

1

理解した:

[42] pry(main)> Post.search(query: {query_string: {query: 'price:>600'}}).size
  Post Search (8.8ms)  curl http://localhost:9200/posts_development/_search?pretty -d '{"query":{"query_string":{"query":"price:\u003e600"}},"size":100000,"from":0,"fields":[]}'
  Post Load (0.5ms)  SELECT "posts".* FROM "posts" WHERE "posts"."id" IN (4, 9, 11, 16, 28, 35, 42, 5, 12, 17, 24, 29, 31, 36, 43, 48, 50, 1, 6, 13, 20, 25, 32, 37, 44, 2, 7, 14, 19, 21, 26, 33, 38, 40, 45, 3, 8, 10, 15, 22, 27, 34, 39, 41, 46)
=> 45

私はまだ理解しfacetていませんが。

于 2015-03-26T03:51:32.997 に答える