我正在尝试修复一些多项搜索,特别是在搜索类似的内容时:

当用户输入“解决这个真棒”时,“这个令人敬畏的游览”要解决 . 管理使其与match_phrase_query一起使用,而不是之前使用query_string查询 .

现在虽然这打破了对复合字段的搜索 . 为了在系统中查找用户,我创建了一个copy_to字段,用于填充,称呼,名字,中间名和姓氏 . 所以它看起来像这样:

"contact": {
    "properties": {
        "contact_full_name": {
            "type": "string"
        },
        "first_name": {
            "copy_to": "contact_full_name",
            "fields": {
                "raw": {
                    "analyzer": "case_insensitive_sort",
                    "ignore_above": 10922,
                    "type": "string"
                }
            },
            "type": "string"
        },
        "last_name": {
            "copy_to": "contact_full_name",
            "fields": {
                "raw": {
                    "analyzer": "case_insensitive_sort",
                    "ignore_above": 10922,
                    "type": "string"
                }
            },
        },
        "middle_name": {
            "copy_to": "contact_full_name",
            "fields": {
                "raw": {
                    "analyzer": "case_insensitive_sort",
                    "ignore_above": 10922,
                    "type": "string"
                }
            },
            "type": "string"
        },
        "salutation": {
            "copy_to": "contact_full_name",
            "fields": {
                "raw": {
                    "analyzer": "case_insensitive_sort",
                    "ignore_above": 10922,
                    "type": "string"
                }
            },
            "type": "string"
        }
    }
}

现在,我发布以下查询:

{
    "fields": "id",
    "from": 0,
    "query": {
        "filtered": {
            "query": {
                "bool": {
                    "minimum_should_match": "1",
                    "must_not": {
                        "term": {
                            "deleted": "true"
                        }
                    },
                    "should": {
                        "match": {
                            "contact_full_name": {
                                "query": "John G",
                                "type": "phrase_prefix"
                            }
                        }
                    }
                }
            }
        }
    },
    "size": 50
}

我没有结果 . 如果我使用“John”作为术语,则返回结果正常 . 我有一种感觉,它与字段复制的顺序有关 . 有没有办法解决这个问题,或者我是否需要使用备用搜索来完成这项工作?

存储的值:

  • 名字:约翰

  • 姓氏:史密斯

  • 中间名:格伦

  • 称呼:先生