2017-02-07 188 views
0

尝试在Elasticsearch中查询w/PHP客户端并优先部分词匹配,但仍包含模糊匹配。如果我删除了address.company匹配块,查询就会按预期工作,但无论我如何对其进行框架化处理,它都会随之崩溃。我在格式化上迷失了,还包括了优先级较低的模糊搜索?Elasticsearch部分匹配或模糊匹配,提升部分结果

$search_data = [ 
     "from" => (int) $start, "size" => (int) $count, 
     'query' => [ 
      'bool' => [ 
       'filter' => [ 
        ['term' => ['active' => 1]], 
        ['term' => ['type' => 2]], 
       ], 
       'must' => [ 
        'wildcard' => [ 
         'address.company' => '*' . $search_query . '*' 
        ], 
        'match' => [ 
         'address.company' => [ 
          'query'  => $search_query, 
          'operator' => 'and', 
          'fuzziness' => 'AUTO', 
         ], 
        ], 
       ], 
      ], 
     ], 
    ]; 
+0

你能分享你的模式映射吗 – user3775217

回答

0

尽管我对ES仍然很陌生,但这种解决方案似乎能够获得我所追求的数据。我只提到,因为如果有人在将来看到这一点,可能会有一个更理想的方式。从必须切换到应该和包装阵列有点不同的伎俩。

$search_data = [ 
    "from" => (int) $start, "size" => (int) $count, 
    'query' => [ 
     'bool' => [ 
      'filter' => [ 
       ['term' => ['active' => 1]], 
       ['term' => ['type' => 2]], 
      ], 
      'should' => [ 
       [ 
        'match' => ['address.company' => ['query'=>$search_query,'boost'=>10]], 
       ], 
       [ 
        'match' => 
        [ 
         'address.company' => 
          [ 
           'query'  => $search_query, 
           'fuzziness' => 'AUTO', 
          ], 
        ], 
       ], 
      ], 
      'minimum_should_match'=>1, 
     ], 
    ], 
];