我是ElasticSearch的新手,致力于跨多个字段获取部分匹配项。例如,假设我为以下三个文档建立了索引:
{
"document-id": "Patient1",
"document-type": "patients",
"firstName": "Benjamin",
"lastName": "Carlton",
"medicalRecordNumber": "111-222-3333"
}
{
"document-id": "Patient2",
"document-type": "patients",
"firstName": "Carly",
"lastName": "Benson",
"medicalRecordNumber": "111-222-3334"
}
{
"document-id": "Patient3",
"document-type": "patients",
"firstName": "Jason",
"lastName": "Benson",
"medicalRecordNumber": "111-222-3335"
}
我想设计一个分析器并搜索查询,以便搜索:
使用以下分析器,我感觉很接近:
{
"settings": {
"analysis": {
"tokenizer": {
"partialMatchTokenizer": {
"type": "edge_ngram",
"min_gram": 2,
"max_gram": 10
}
},
"analyzer": {
"partialMatchAnalyzer": {
"type": "custom",
"tokenizer": "partialMatchTokenizer",
"char_filter": [],
"filter": [
"lowercase"
]
}
}
}
},
"mappings": {
"_doc": {
"properties": {
"lastName": {
"type": "text",
"analyzer": "partialMatchAnalyzer"
},
"firstName": {
"type": "text",
"analyzer": "partialMatchAnalyzer"
}
}
}
}
}
以及以下查询:
{
"query": {
"multi_match": {
"query": "carlt ben",
"type": "cross_fields",
"fields": [
"firstName",
"lastName",
"medicalRecordNumber"
],
"operator": "or"
}
}
}
但是还不完全是。 “或”似乎太宽容; “和”似乎过于严格。 有时n-gram匹配似乎提供了意外的结果。例如,上面的查询(“ carlt ben”)与#1和#2都匹配(即,“ carlt”与“ Carly”匹配,这可能是因为“ carl” n-gram匹配)。 同样,奇怪的是,“ carlt ben”和“ ben carlt”提供了两个不同的结果集(#1&#2与#1&#2&#3)。
关于我需要如何更改分析仪和/或查询以获得上述结果的任何想法?