弹性搜索 - copy_to字段

时间:2016-07-28 16:57:23

标签: elasticsearch

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

"这个令人敬畏的短途旅行"在用户输入时解决:"这个真棒"。管理使其与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"作为术语,它返回结果很好。我有一种感觉,它与字段复制的顺序有关。有没有办法让我解决这个问题,或者我是否需要使用备用搜索来完​​成这项工作?

存储的值:

  • 名字:John
  • 姓氏:史密斯
  • 中间名:格伦
  • 称呼:先生

0 个答案:

没有答案