600").size Post Search (18.7ms) curl http-6ren">
gpt4 book ai didi

elasticsearch - Searchkick-查询字符串查询

转载 作者:行者123 更新时间:2023-12-02 23:37:24 27 4
gpt4 key购买 nike

从这个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

关于elasticsearch - Searchkick-查询字符串查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29270759/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com