gpt4 book ai didi

ruby-on-rails - Elasticsearch,multi_match,ruby上的ruby

转载 作者:行者123 更新时间:2023-12-02 22:40:42 24 4
gpt4 key购买 nike

我想使用ElasticSearch搜索我的产品集合。

如果我有这样的对象:

{ name: "Product Name", producer: "Best Producer"}

我想通过搜索找到该对象:
  • 产品
  • bes
  • 专业版
  • 名称
  • 生产者
  • 最佳产品
  • 最好的名字

  • 等等

    这段代码很好用,但是例如“name”不是前缀:
    Product.search(
    {
    multi_match: {
    query: params[:search_input],
    type: "phrase_prefix",
    fields: ["name", "producer"],
    operator: "and"
    }
    })

    如何改善呢?

    最佳答案

    您可以将bool,should和term用作多重匹配参数。

           Product.search(:query => @query)

    @query = {
    :bool => {
    :must => @must_queries
    }
    }

    :bool => {
    :should => [
    {
    :terms => {
    :your_mathcing_field_name => value
    }
    }
    ]
    }

    您可以为每个字段输入多个术语。

    关于ruby-on-rails - Elasticsearch,multi_match,ruby上的ruby,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31700255/

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