Elasticsearch-如何从查询中进行部分匹配 [英] Elasticsearch - How to do a partial match from your query

查看:95
本文介绍了Elasticsearch-如何从查询中进行部分匹配的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对Elasticsearch有点陌生,我想知道如何对特定文件进行查询的部分匹配.

I am a bit new to Elasticsearch and I am wondering how it is possible to do a partial match of a query on a particular filed.

让我们说我有一个叫做部门"的字段,它的值是"accounting".因此,当我搜索会计"之类的内容时,我应该能够得到结果.

Lets say I have a field called "department" and it has a value "accounting". So when I search for something like "The accounting", I should be able to get the result.

例如:-以下是我的两个文件:

eg:- Below are my two documents:

{
   "name": "Joe",
   "department": "finance"
},
{
   "name": "Matt",
   "department": "accounting"
}

我在字段department上的搜索查询是The accountingThe accounting department,我的预期结果应该是:

My search query on the field department is The accounting or The accounting department and my expected result should be:

{
   "name": "Matt",
   "department": "accounting"
}

更新:

@Russ Cam:标准"分析器会删除所有标点符号和特殊字符,如果我将现场部门的值另存为dept/accounting,并且当我搜索dept: the dept/accounting时应该怎么办?值作为dept/accounting.

@Russ Cam: The Standard analyzer removes all the punctuation and special characters so what if I have the value in the field department saved as dept/accounting and when i search for dept: the dept/accounting I should get those documents that have the department value as dept/accounting.

当有人搜索deptaccounting时,我不希望ES向我提供部门名称为dept/accounting的文档.这可能吗?

I don't want ES to give me documents with the department as dept/accounting when someone searches for dept or accounting. Is this possible?

假设以下是我在ES中的文档:

Assume that the following are my documents in ES:

{
   "name": "Matt",
   "department": "dept/accounting"
},
{
   "name": "Kate",
   "department": "dept"
},
{
   "name": "Adam",
   "department": "accounting"
}

用户搜索dept,他得到:

{
  "name": "Kate",
  "department": "dept"
}

当用户搜索blah blah dept/accounting blah时,他应该只会得到以下信息:

When the user searches for blah blah dept/accounting blah he should get only this:

{
   "name": "Matt",
   "department": "dept/accounting"
}

推荐答案

您是否尝试过匹配查询,这应该对您有用

Have you tried match query ,this should work for you

{
  "query": {
    "match": {
      "department": "accounting"
    }
  }

这篇关于Elasticsearch-如何从查询中进行部分匹配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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