我对Elasticsearch有点新意,我想知道如何对特定字段的查询进行部分匹配。
假设我有一个名为" department"它有一个价值"会计"。因此,当我搜索"会计"之类的东西时,我应该能够得到结果。
例如: - 以下是我的两份文件:
{
"name": "Joe",
"department": "finance"
},
{
"name": "Matt",
"department": "accounting"
}
我对department
字段的搜索查询为The accounting
或The accounting department
,我的预期结果应为:
{
"name": "Matt",
"department": "accounting"
}
更新:
@Russ Cam:标准分析器会删除所有标点符号和特殊字符,这样如果我将字段部门中的值保存为dept/accounting
,当我搜索dept: the dept/accounting
时,我应该获取这些文档部门值为dept/accounting
的部分。
当有人搜索dept/accounting
或dept
时,我不希望ES以accounting
向部门提供文档。这可能吗?
假设以下是我在ES中的文件:
{
"name": "Matt",
"department": "dept/accounting"
},
{
"name": "Kate",
"department": "dept"
},
{
"name": "Adam",
"department": "accounting"
}
用户搜索dept
并获得:
{
"name": "Kate",
"department": "dept"
}
当用户搜索blah blah dept/accounting blah
时,他应该只获得此信息:
{
"name": "Matt",
"department": "dept/accounting"
}
答案 0 :(得分:0)
默认情况下,Elasticsearch支持最佳匹配方法,默认布尔运算符为OR
。这应该是开箱即用的,例如Query String
查询,请参阅https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-query-string-query.html
答案 1 :(得分:0)
您是否尝试过匹配查询,这应该适合您
{
"query": {
"match": {
"department": "accounting"
}
}