Searchkick - 查询字符串查询
Searchkick - Query String Query
从这个page,我正在尝试这个:
[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
为什么这两个有不同的输出有什么建议吗?可能是转义字符 "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
,谁能帮我解决这个问题?
这个问题也是here。
想通了:
[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
从这个page,我正在尝试这个:
[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
为什么这两个有不同的输出有什么建议吗?可能是转义字符 "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
,谁能帮我解决这个问题?
这个问题也是here。
想通了:
[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