Elasticsearch:如何在渗滤器查询中使用通配符

时间:2018-08-09 19:01:21

标签: elasticsearch elasticsearch-dsl

我正在创建一些类似于以下查询的过滤器查询:

{
    "search_term": "*a1c*",
    "highlight": {
        "fields": [
            "assessment",
            "complaint",
            "exam",
            "history"
         ],
        "post_tags": [
            "~~"
        ],
        "pre_tags": [
            "~~"
        ]
    },
    "query": {
        "multi_match": {
            "fields": [
                "assessment",
                "complaint",
                "exam",
                "history",
            ],
            "query": "*a1c*",
            "type": "phrase"
        }
    }
}

我想要的是搜索

之类的文档
"patient's hemoglobin a1c is ..."

并返回结果

"patient's hemoglobin ~~a1c~~ is..."

当前正在使用上面的查询。但是,我希望它也可以在子字符串中找到术语“ a1c”,例如

"patient's hba1c is..."

 "patientsa1cmeasurementis..."

但是,elasticsearch仅将“ a1c”作为独立字符串进行匹配,尽管在搜索词中使用了通配符,也无法识别子字符串。我在这里做错了什么?如果有帮助,我不在乎执行时间(我知道通配符很慢),并且保持突出显示会很棒,但是如果两者是互斥的,那么我可以摆脱它。

1 个答案:

答案 0 :(得分:0)

尝试将您的multi_search更改为

"query":{
  "query_string":{
     "query":"*a1c*",
     "fields":[
        "assessment",
        "complaint",
        "exam"
     ]
  }}

使用此查询,“ patient's hba1c is...”将为“ patient's ~~hba1c~~ is...” 和 “ patientsa1cmeasurementis...”将是"~patientsa1cmeasurementis...~~"