elasticsearch - ElasticSearch 多匹配子字符串搜索
问题描述
我必须结合两个过滤器来匹配要求: - r.status 字段中的特定值列表 - 多个文本字段之一包含该值。结果查询(使用 using Nest
,但没关系)如下所示:
{
"query": {
"bool": {
"filter": [
{
"bool": {
"must": [
{
"term": {
"isActive": {
"value": true
}
}
},
{
"nested": {
"query": {
"bool": {
"must": [
{
"terms": {
"r.status": [
"VALUE_1",
"VALUE_2",
"VALUE_3"
]
}
},
{
"bool": {
"should": [
{
"match": {
"r.g.firstName": {
"type": "phrase",
"query": "SUBSTRING_VALUE"
}
}
},
{
"match": {
"r.g.lastName": {
"type": "phrase",
"query": "SUBSTRING_VALUE"
}
}
}
]
}
}
]
}
},
"path": "r"
}
}
]
}
}
]
}
}
}
还尝试了 multi_match 查询:
{
"query": {
"bool": {
"filter": [
{
"bool": {
"must": [
{
"term": {
"isActive": {
"value": true
}
}
},
{
"nested": {
"query": {
"bool": {
"must": [
{
"terms": {
"r.status": [
"VALUE_1",
"VALUE_2",
"VALUE_3"
]
}
},
{
"multi_match": {
"query": "SUBSTRING_VALUE",
"fields": [
"r.g.firstName",
"r.g.lastName"
]
}
}
]
}
},
"path": "r"
}
}
]
}
}
]
}
}
}
FirstName
并LastName
在索引映射中配置为text
:
"firstName": {
"type": "text"
},
"lastName": {
"type": "text"
}
Elastic 提供了很多全文搜索选项:multi_match
、phrase
等wildcards
。但在我的情况下,它们都失败了,在我的文本字段中查找子字符串。(terms
查询和isActive
一个运行良好,我只是尝试只运行它们)。
我还有什么选择,或者我可能在哪里犯了错误?
UPD:组合通配符对我有用,但这样的查询看起来很难看。寻找更优雅的解决方案。
解决方案
推荐阅读
- php - Symonfy2 我有一个用户实体,它需要一个技能集实体
- javascript - 在没有数据库的情况下保存和检索登录和注册表单
- r - 使用符号或“|” 在 r
- c++ - C++ - Bool 到 int 的转换错误
- sqoop - 从 shell 中的 sqoop 导入中捕获结果代码
- reactjs - 在两个组件上反应路由器一个路径点
- html - 打印时没看到
- php - array_set - 转义变量以允许句号
- amazon-web-services - 使用 AWS AutoScaling 安排启动和停止 EC2 实例的效率如何?
- java - 为什么 Repaint() 和 add() 方法不起作用?