douwo1517 2016-07-02 10:53
浏览 164

Elasticsearch中的精确匹配(Facet搜索)

I am planning to turn my search and filtering engines into Elasticsearch. By looking into a lot documentation I found that elasticsearch has the ability create facets. I made some facets into my left filter navigation sidebar and query my products and facets by filtering them using category field in elasticsearch.

But the thing is I don't know how to query back into elasticsearch for selected facets.

I used

'filter' => [
    'bool' => [
        'must' => [
            ['match_phrase' => [ 'Material' => 'Aluminum' ]],
            ['match_phrase' => [ 'Length' => '1/2']]
         ]
     ]
 ]

this code in body tag of elasticsearch php client. It actually works but I have other products that has Length 1/2-3 or 1/2-4. When I queried for 1/2, Elastic also gets 1/2-3 and 1/2-4 because '1/2-3' and '1/2-4' contains also '1/2'.

I wonder how to search and get exactly products that have 1/2 not 1/2-3 or 1/2-4 what query should I have to use exactly?

Thanks!

Note : Facets are deprecated I know. I am using that word because I am used to it. It's now aggregations in Elasticsearch 2.3. and I am using that version.*

  • 写回答

1条回答 默认 最新

  • doueta6642 2016-07-02 11:01
    关注

    Got my solution!

    Instead of match_phrase I used term method. It gets exactly what I need. It searches exact match not contained match instead of match_phrase. Match_phrase is searching exact phrase side by side.

    But for term you need to create fields with not_analyzed for exact result.

    评论

报告相同问题?

悬赏问题

  • ¥15 thinkphp6配合social login单点登录问题
  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch