elasticsearch 按子串匹配
我需要获取
elasticsearch 按子串匹配,
elasticsearch,
elasticsearch,我需要获取Description字段包含子字符串28/859的文档。我的问题是: { "explain": true, "query": { "bool":{ "filter":{ "bool":{"should":[{"query_string":{"default_field":"Description","query":"28//859", "analyzer
Description
字段包含子字符串28/859
的文档。我的问题是:
{
"explain": true,
"query": {
"bool":{
"filter":{
"bool":{"should":[{"query_string":{"default_field":"Description","query":"28//859",
"analyzer": "keyword"}}]}},
"must_not":{"exists":{"field":"ParentId"}}}
}
}
我通过以下方式获得文件:
在28/859
字段中(很好)Description
- 但是我也可以在
字段中获取带有Description
的文档(我不需要它)28
28/859
的文档
更新:解释示例:
{
"_shard": "[tech_places][4]",
"_node": "u7QI_gjjRXy4-xdqnK2KMw",
"_index": "tech_places",
"_type": "entity",
"_id": "8403",
"_score": 0.0,
"_source": {
"Id": 8403,
"Name": "RETE-43424",
"Description": "SRF-10kv №28 VISO",
"ParentId": null,
"OrganizationId": 12,
"OrganizationPath": "12_27",
"LocationId": 27,
"Classification": "",
"Type": "A",
"Status": 0,
"MaintenanceObjectId": null,
"TreePath": "8403"
},
"_explanation": {
"value": 0.0,
"description": "sum of:",
"details": [
{
"value": 0.0,
"description": "match on required clause, product of:",
"details": [
{
"value": 0.0,
"description": "# clause",
"details": []
},
{
"value": 0.0,
"description": "sum of:",
"details": [
{
"value": 0.0,
"description": "weight(Description:28 in 35112) [], result of:",
"details": [
{
"value": 0.0,
"description": "score(doc=35112,freq=1.0), with freq of:",
"details": [
{
"value": 1.0,
"description": "termFreq=1.0",
"details": []
}
]
}
]
}
]
}
]
}
]
}
},
您可以为此使用
空白
分析器。使用description
属性创建/更新映射,如下所示:
{
"description": {
"type": "text",
"analyzer": "whitespace"
}
}
这将确保像28/859这样的东西被视为s的单个令牌。您甚至可以使用正则表达式创建自己的自定义标记器/分析器。然后,您可以使用下面的查询来获得所需的结果:
{
"query": {
"query_string": {
"default_field": "description",
"query": "28\\/859"
}
}
}
应该符合要求
示例代码:
GET <indexname>/_search
{
"query": {
"bool": {
"must": [
{
"match_phrase": {
"Description": """28/859"""
}
}
]
}
}
}
GET/\u搜索
{
“查询”:{
“布尔”:{
“必须”:[
{
“匹配短语”:{
说明:“28/859”
}
}
]
}
}
}
您能为查询添加explain:true并显示输出吗?@mystion,我已经更新了我的问题。它仅在28/859
完整描述
时有效,但在我的情况下,它只是一个子字符串。您尝试过吗?当28/859是相同顺序的字符串的一部分时,这意味着用于字段描述。不过,您也可以尝试以下操作:GET/_search{“query”:{“bool”:{“must”:[{“match_phrase”:{“Description”:“28”},{“match_phrase”:{“Description”:“/859”}}}}谢谢,它对我有帮助。