我看到Model.search和SearchKick.search的索引名称不同。
我正在尝试将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 弹性搜寻版本: 版本:6.5.2,构建:default / tar / 9434bed / 2018-11-29T23:58:20.891072Z,JVM:1.8.0_20
对于深入了解此问题的任何帮助将不胜感激
答案 0 :(得分:0)
我不确定您是否可以使用Searchkick搜索多个索引,请参见https://github.com/ankane/searchkick/issues/744这个问题
但是您可以执行以下操作:
Searchkick.search "milk", index_name: [Product, Category]
但是,如果您在这里elasticsearch - querying multiple indexes is possible?
,可以通过一些猴子补丁来使用它