[英]Elasticsearch - How to do a partial match from your query
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. 我对Elasticsearch有点陌生,我想知道如何对特定文件进行查询的部分匹配。
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"
}
My search query on the field department
is The accounting
or The accounting department
and my expected result should be: 我在外勤
department
搜索查询是The accounting
或The accounting department
,我的预期结果应该是:
{
"name": "Matt",
"department": "accounting"
}
UPDATE: 更新:
@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
. @Russ Cam:标准分析器会删除所有标点符号和特殊字符,如果我将外地部门中的值保存为
dept/accounting
,当我搜索dept: the dept/accounting
时该怎么办dept: the dept/accounting
我应该得到那些拥有部门的文档值作为dept/accounting
。
I don't want ES to give me documents with the department as dept/accounting
when someone searches for dept
or accounting
. 我不希望ES在有人搜索
dept
或accounting
时向我提供部门部门的文件作为dept/accounting
accounting
。 Is this possible? 这可能吗?
Assume that the following are my documents in ES: 假设以下是我在ES中的文档:
{
"name": "Matt",
"department": "dept/accounting"
},
{
"name": "Kate",
"department": "dept"
},
{
"name": "Adam",
"department": "accounting"
}
The user searches for dept
and he gets: 用户搜索
dept
,他得到:
{
"name": "Kate",
"department": "dept"
}
When the user searches for blah blah dept/accounting blah
he should get only this: 当用户搜索
blah blah dept/accounting blah
他应该只会得到以下信息:
{
"name": "Matt",
"department": "dept/accounting"
}
By default Elasticsearch is supporting the best match approach and the default Boolean operator is the OR
. 默认情况下,Elasticsearch支持最佳匹配方法,默认布尔运算符为
OR
。 This should work out-of-the-box with for example the Query String
query, see https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-query-string-query.html 这应该可以立即使用,例如
Query String
查询,请参阅https://www.elastic.co/guide/zh-CN/elasticsearch/reference/current/query-dsl-query-string-query.html
Have you tried match query ,this should work for you 您是否尝试过匹配查询,这应该适合您
{
"query": {
"match": {
"department": "accounting"
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.