Elasticsearch精确匹配词组 [英] Elasticsearch exact match pharse

查看:67
本文介绍了Elasticsearch精确匹配词组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在Elasticsearch中搜索一个词组以查找完全匹配.但是Elasticsearch也给出了其他包含的词组.

一个例子;我想搜索小猫",但Elasticsearch返回小猫跳",小猫",小猫救死了婴儿"等.

我只想要确切的,只有小猫",而不是其他.我该如何查询?

我的内容喜欢;

  {标题:小猫",内容:"bla bla bla"},... 

解决方案

这很大程度上取决于 title 的索引方式.对于此类要求,标题必须为分析为 keyword ,这意味着 title 中的任何文本都与ES内部Lucene倒排索引中的文本完全一样.

并且 term 过滤器将是搜索以 keyword 分析的 title 中的 little cat 的选择./p>

如果您希望在编制索引时对 title 字段进行其他操作,则可以

I just want exact and only "little cat", not the others. How can I do this query?

My contents like;

{
    title: "little cat",
    content: "bla bla bla"
},
...

解决方案

It depends a lot on how title is indexed. For such a requirement, title would need to be analyzed as keyword, meaning whatever text is in title exactly like that is put in ES' internal Lucene inverted index.

And a term filter would be the choice for searching little cat in title analyzed as keyword.

If you want to have other operations made to your title field at indexing time, you can add a filter, for example for lowercasing any upper-case letters. But, in any case, you DO need a keyword analyzer.

If you don't want to change how title is being indexed now, you can make it as multi_field and add a title_keyword (for example) field that should be indexed using your keyword analyzer.

这篇关于Elasticsearch精确匹配词组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆