我从Model.search和SearchKick.search看到带有index_name的不同结果。
我正在尝试将cross_fields查询应用于多个索引。我得到了一些奇怪的结果,所以我开始根据单个索引检查查询,在这种情况下,尽管searchkick查询对象完全相同,但我还是得到了血清结果返回
cross_field_query = {
body: {
query: {
multi_match: {
query: query,
type: "cross_fields",
operator: "and"
}
}
}
}
results = TaggedTree.search cross_field_query
results.total_count -> 29
results = Searchkick.search cross_field_query, index_name: [TaggedTree]
results.total_count -> 0
我使用execute执行查询:false,它们似乎是相同的。这是to_curl的输出
results = TaggedTree.search advanced_query, execute: false
results.to_curl
"curl http://localhost:9200/tagged_trees_development/_search?pretty -H 'Content-Type: application/json' -d '{\"query\":{\"dis_max\":{\"queries\":[{\"multi_match\":{\"query\":\"{:body=\\u003e{:query=\\u003e{:multi_match=\\u003e{:query=\\u003e\\\"oak malahide\\\", :type=\\u003e\\\"cross_fields\\\", :operator=\\u003e\\\"and\\\"}}}}\",\"boost\":10,\"operator\":\"and\",\"analyzer\":\"searchkick_search\",\"fields\":[\"*.analyzed\"],\"type\":\"best_fields\"}},{\"multi_match\":{\"query\":\"{:body=\\u003e{:query=\\u003e{:multi_match=\\u003e{:query=\\u003e\\\"oak malahide\\\", :type=\\u003e\\\"cross_fields\\\", :operator=\\u003e\\\"and\\\"}}}}\",\"boost\":10,\"operator\":\"and\",\"analyzer\":\"searchkick_search2\",\"fields\":[\"*.analyzed\"],\"type\":\"best_fields\"}},{\"multi_match\":{\"query\":\"{:body=\\u003e{:query=\\u003e{:multi_match=\\u003e{:query=\\u003e\\\"oak malahide\\\", :type=\\u003e\\\"cross_fields\\\", :operator=\\u003e\\\"and\\\"}}}}\",\"boost\":1,\"operator\":\"and\",\"analyzer\":\"searchkick_search\",\"fuzziness\":1,\"prefix_length\":0,\"max_expansions\":3,\"fuzzy_transpositions\":true,\"fields\":[\"*.analyzed\"],\"type\":\"best_fields\"}},{\"multi_match\":{\"query\":\"{:body=\\u003e{:query=\\u003e{:multi_match=\\u003e{:query=\\u003e\\\"oak malahide\\\", :type=\\u003e\\\"cross_fields\\\", :operator=\\u003e\\\"and\\\"}}}}\",\"boost\":1,\"operator\":\"and\",\"analyzer\":\"searchkick_search2\",\"fuzziness\":1,\"prefix_length\":0,\"max_expansions\":3,\"fuzzy_transpositions\":true,\"fields\":[\"*.analyzed\"],\"type\":\"best_fields\"}}]}},\"timeout\":\"11s\",\"_source\":false,\"size\":10000,\"from\":0}'"
results = Searchkick.search index_advanced_query, index_name: TaggedTree, execute: false
results.to_curl
"curl http://localhost:9200/tagged_trees_development/_search?pretty -H 'Content-Type: application/json' -d '{\"query\":{\"dis_max\":{\"queries\":[{\"multi_match\":{\"query\":\"{:body=\\u003e{:query=\\u003e{:multi_match=\\u003e{:query=\\u003e\\\"oak malahide\\\", :type=\\u003e\\\"cross_fields\\\", :operator=\\u003e\\\"and\\\"}}}}\",\"boost\":10,\"operator\":\"and\",\"analyzer\":\"searchkick_search\",\"fields\":[\"*.analyzed\"],\"type\":\"best_fields\"}},{\"multi_match\":{\"query\":\"{:body=\\u003e{:query=\\u003e{:multi_match=\\u003e{:query=\\u003e\\\"oak malahide\\\", :type=\\u003e\\\"cross_fields\\\", :operator=\\u003e\\\"and\\\"}}}}\",\"boost\":10,\"operator\":\"and\",\"analyzer\":\"searchkick_search2\",\"fields\":[\"*.analyzed\"],\"type\":\"best_fields\"}},{\"multi_match\":{\"query\":\"{:body=\\u003e{:query=\\u003e{:multi_match=\\u003e{:query=\\u003e\\\"oak malahide\\\", :type=\\u003e\\\"cross_fields\\\", :operator=\\u003e\\\"and\\\"}}}}\",\"boost\":1,\"operator\":\"and\",\"analyzer\":\"searchkick_search\",\"fuzziness\":1,\"prefix_length\":0,\"max_expansions\":3,\"fuzzy_transpositions\":true,\"fields\":[\"*.analyzed\"],\"type\":\"best_fields\"}},{\"multi_match\":{\"query\":\"{:body=\\u003e{:query=\\u003e{:multi_match=\\u003e{:query=\\u003e\\\"oak malahide\\\", :type=\\u003e\\\"cross_fields\\\", :operator=\\u003e\\\"and\\\"}}}}\",\"boost\":1,\"operator\":\"and\",\"analyzer\":\"searchkick_search2\",\"fuzziness\":1,\"prefix_length\":0,\"max_expansions\":3,\"fuzzy_transpositions\":true,\"fields\":[\"*.analyzed\"],\"type\":\"best_fields\"}}]}},\"timeout\":\"11s\",\"_source\":false,\"size\":10000,\"from\":0}'"
searchkick版本:3.1.2
flex 搜寻版本:
版本:6.5.2,构建:default / tar / 9434bed / 2018-11-29T23:58:20.891072Z,JVM:1.8.0_20
深入了解此问题的任何帮助将不胜感激
最佳答案
我不确定您可以使用Searchkick在多个索引中进行搜索,请参见https://github.com/ankane/searchkick/issues/744
但是您可以执行以下操作:
Searchkick.search "milk", index_name: [Product, Category]
但是,如果您在这里看看elasticsearch - querying multiple indexes is possible?,则可能可以使其与某些猴子修补程序一起使用
关于ruby - 来自named.index的Model.search和SearchKick.search不同的结果,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/55109459/