Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/35.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
<img src="//i.stack.imgur.com/RUiNP.png" height="16" width="18" alt="" class="sponsor tag img">elasticsearch 弹性搜索-多字段模糊严格匹配_<img Src="//i.stack.imgur.com/RUiNP.png" Height="16" Width="18" Alt="" Class="sponsor Tag Img">elasticsearch_Searchkick - Fatal编程技术网 elasticsearch 弹性搜索-多字段模糊严格匹配,elasticsearch,searchkick,elasticsearch,Searchkick" /> elasticsearch 弹性搜索-多字段模糊严格匹配,elasticsearch,searchkick,elasticsearch,Searchkick" />

elasticsearch 弹性搜索-多字段模糊严格匹配

elasticsearch 弹性搜索-多字段模糊严格匹配,elasticsearch,searchkick,elasticsearch,Searchkick,我们想利用ElasticSearch找到相似的对象 假设我有一个具有4个字段的对象: 产品名称、卖家名称、卖家电话、平台id 类似的产品在不同的平台上可以有不同的产品名称和销售商名称(模糊匹配) 然而,电话是严格的,单一的变化可能会导致产生一个错误的记录(严格匹配) 我们试图创建的查询将: 考虑当前记录的所有字段和/或 在他们之间 授权平台id是我想具体查看的。(及) 模糊产品名称和卖家名称 严格匹配电话号码,或在字段中或字段之间忽略它 如果我用伪代码编写,我会编写如下内容: ((产品名称,如“

我们想利用ElasticSearch找到相似的对象

假设我有一个具有4个字段的对象: 产品名称、卖家名称、卖家电话、平台id

类似的产品在不同的平台上可以有不同的产品名称和销售商名称(模糊匹配)

然而,电话是严格的,单一的变化可能会导致产生一个错误的记录(严格匹配)

我们试图创建的查询将:

  • 考虑当前记录的所有字段和/或 在他们之间
  • 授权平台id是我想具体查看的。(及)
  • 模糊产品名称和卖家名称
  • 严格匹配电话号码,或在字段中或字段之间忽略它 如果我用伪代码编写,我会编写如下内容:

    ((产品名称,如“某些产品名称”)或(卖方名称,如 'some_seller_name')或(seller_phone='some_phone')和(platform_id =123)


    为了在
    seller\u电话
    上进行精确匹配,我在不使用ngram分析仪的情况下为该字段编制索引,同时为
    product\u name
    seller\u name

    映射

    PUT index111
    {
      "settings": {
        "analysis": {
          "analyzer": {
            "edge_n_gram_analyzer": {
              "tokenizer": "whitespace",
              "filter" : ["lowercase",  "ednge_gram_filter"]
            }
          },
          "filter": {
          "ednge_gram_filter" : {
            "type" : "NGram",
            "min_gram" : 2,
            "max_gram": 10
          }
          }
        }
      },
      "mappings": {
        "document_type" : {
          "properties": {
            "product_name" : {
              "type": "text",
              "analyzer": "edge_n_gram_analyzer"
            },
            "seller_name" : {
              "type": "text",
              "analyzer": "edge_n_gram_analyzer"
            },
            "seller_phone" : {
              "type": "text"
            },
            "platform_id" : {
              "type": "text"
            }
          }
        }
      }
    }
    
    索引文档

    POST index111/document_type
    {
           "product_name":"macbok",
           "seller_name":"apple",
           "seller_phone":"9988",
           "platform_id":"123"
    }
    
    用于以下伪sql查询

    ((product_name like 'some_product_name') OR (seller_name like 'some_seller_name') OR (seller_phone = 'some_phone')) AND (platform_id = 123)
    
    弹性查询

    POST index111/_search
    {
        "query": {
            "bool": {
                "must": [
                  {
                    "term": {
                      "platform_id": {
                        "value": "123"
                      }
                    }
                  },
                  {
                    "bool": {
                        "should": [{
                                "fuzzy": {
                                    "product_name": {
                                        "value": "macbouk",
                                        "boost": 1.0,
                                        "fuzziness": 2,
                                        "prefix_length": 0,
                                        "max_expansions": 100
                                    }
                                }
                            },
                            {
                                "fuzzy": {
                                    "seller_name": {
                                        "value": "apdle",
                                        "boost": 1.0,
                                        "fuzziness": 2,
                                        "prefix_length": 0,
                                        "max_expansions": 100
                                    }
                                }
                            },
                            {
                              "term": {
                                "seller_phone": {
                                  "value": "9988"
                                }
                              }
                            }
                        ]
                    }
                }]
            }
        }
    }
    

    希望这能有所帮助

    我们使用的是Searchkick gem,因此任何使用它或直接查询ES的解决方案都将非常适合我们:)我使用chewy,我可以将确切的elastic查询has哈希传递给chewy elastic客户端。我不知道如何实现这一点与搜索踢。这看起来很棒。我会仔细研究一下你的样品,看看能否让它发挥作用:)