我有一个ElasticSearch索引,包含以下文档:
"hits": [
{
"_index": "myindex",
"_type": "mytype",
"_id": "90323",
"_source": {
"codeId": "90323",
"code": "A01",
"code_raw": "A01",
"description": "Desc for A01",
},
},
{
"_index": "myindex",
"_type": "mytype",
"_id": "90324",
"_source": {
"codeId": "90324",
"code": "A01.2",
"code_raw": "A012",
"description": "Desc for A01.2",
},
},
{
"_index": "myindex",
"_type": "mytype",
"_id": "90325",
"_source": {
"codeId": "90325",
"code": "A01.3",
"code_raw": "A013",
"description": "Desc for A01.3",
},
},
{
"_index": "icd",
"_type": "icd10",
"_id": "90326",
"_source": {
"codeId": "90326",
"code": "A01.34",
"code_raw": "A0134",
"description": "Desc for A01.34",
},
},
{
"_index": "myindex",
"_type": "mytype",
"_id": "90327",
"_source": {
"codeId": "90327",
"code": "A01.35",
"code_raw": "A0135",
"description": "Desc fro A01.35",
},
"sort": [
"Z1321"
]
},
{
"_index": "myindex",
"_type": "mytype",
"_id": "90328",
"_score": null,
"_source": {
"codeId": "90328",
"code": "A01.356",
"code_raw": "A01356",
"description": "Desc for A01.356",
},
},
{
"_index": "myindex",
"_type": "mytype",
"_id": "90329",
"_source": {
"codeId": "90329",
"code": "A01.359",
"code_raw": "A01359",
"description": "Desc for A01.359",
},
},
...
]
我通常使用类似于GET http://[host:port]/myindex/mytype/_search
的查询来查询子对象:
"query":{
"match_phrase_prefix":{
"code_raw":"A01"
}
}
现在我需要反向任务,例如code_raw A01359,我需要文档A01359、A0135、A013和A01,有没有简单的方法使用elasticsearch?,或者我只是单独预处理每个文档的代码和查询?
1条答案
按热度按时间zbwhf8kr1#
我的建议是创建一个新的分析器,这个分析器使用标记器edge_ngram。
但是这个分析器只在搜索时使用search_analyzer。
这允许创建令牌,如:
令牌:
这样,就可以匹配其他文档的code_raw字段中的值。
完整示例:
质询
结果: