【问题标题】:different results from Model.search and SearchKick.search with a named_index来自 Model.search 和 SearchKick.search 的不同结果,带有 named_index
【发布时间】:2019-03-11 19:58:18
【问题描述】:

我看到 Model.search 和 SearchKick.search 的结果不同,带有 index_name。

我正在尝试将 cross_fields 查询应用于多个索引。我得到了一些奇怪的结果,所以我开始对单个索引的查询进行健全性检查,在这种情况下,尽管 searchkick 查询对象是相同的,但据我所知,我得到了返回的 sero 结果

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

非常感谢您提供任何帮助了解这一点的帮助

【问题讨论】:

  • 如果您尝试不带索引名称的Searchkick.search cross_field_query 会发生什么?
  • @lacostenycoder 感谢您的回复。它似乎刚刚达到第一个索引,但我确实得到了一组结果。问题是最终我想跨两个索引运行查询,我在 searchkick 文档中找不到任何关于在哪里指定要定位的索引集的内容
  • query: query,query的值是怎么定义的?
  • 它只是一个字符串,比如“烤土豆”、“伦敦餐厅”等。

标签: ruby elasticsearch searchkick


【解决方案1】:

我不确定您是否可以使用 Searchkick 搜索多个索引,请参阅此问题 https://github.com/ankane/searchkick/issues/744

但您可以执行以下操作:

Searchkick.search "milk", index_name: [Product, Category]

但是,如果您在此处查看 elasticsearch - querying multiple indexes is possible?

【讨论】:

  • @lacotenycoder 感谢您的回复。对此,我真的非常感激。是的,我一直在使用多索引查询,但我想转而使用 cross_fields 来改进结果。我认为阅读文档应该可以传入查询正文并指定索引,但似乎没有。也许我应该看看直接使用 elasticsearch-ruby 客户端
  • @Conor 是的,值得一试。您是否使用导轨?
猜你喜欢
  • 1970-01-01
  • 2016-08-13
  • 2019-06-28
  • 1970-01-01
  • 2012-12-21
  • 2020-03-17
  • 1970-01-01
  • 2022-01-05
  • 2021-03-07
相关资源
最近更新 更多