多匹配布尔增强

时间:2013-10-11 16:24:08

标签: elasticsearch

我正在尝试执行以下操作

curl -X POST localhost:9200/magento/customer/_search?pretty=1 -d '
{
    "query": {
        "bool": {
            "must": [
                {
                    "multi_match": {
                        "query": "john",
                        "fields": [
                            "firstname"
                        ],
                        "type": "phrase_prefix"
                    }
                }
            ],
            "should": [
                {
                    "multi_match": {
                        "query": "bro",
                        "fields": [
                            "lastname"
                        ],
                        "type": "phrase_prefix",
                        "boost": 10
                    }
                },
                {
                    "multi_match": {
                        "query": "sul",
                        "fields": [
                            "lastname"
                        ],
                        "type": "phrase_prefix",
                        "boost": 1
                    }
                }
            ]
        }
    }
}
'

在Johnnie BrousXXXX(编辑)之前,它正在将Johnnie SultXXXX的结果归还给我。

好像没有正确应用提升?我试过检查一下关于布尔值的elasticsearch文档: http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-bool-query.html

他们在boost节点下面有bool并没有任何意义,你通常想要提升一个特定的布尔should ...?< / p>

更新:

创建索引时我没有创建任何字段映射。

以下是explain

的结果
{
    "ok": true,
    "_index": "magento",
    "_type": "customer",
    "_id": "6043",
    "matched": true,
    "explanation": {
    "value": 2.3943894,
        "description": "product of:",
        "details": [
            {
                "value": 3.591584,
                "description": "sum of:",
                "details": [
                    {
                        "value": 1.795792,
                        "description": "sum of:",
                        "details": [
                            {
                                "value": 1.795792,
                                "description": "weight(firstname:johnnie in 8931) [PerFieldSimilarity], result of:",
                                "details": [
                                    {
                                        "value": 1.795792,
                                        "description": "score(doc=8931,freq=1.0 = termFreq=1.0\n), product of:",
                                        "details": [
                                            {
                                                "value": 0.18156901,
                                                "description": "queryWeight, product of:",
                                                "details": [
                                                    {
                                                        "value": 9.89041,
                                                        "description": "idf(docFreq=1, maxDocs=14524)"
                                                    },
                                                    {
                                                        "value": 0.018358087,
                                                        "description": "queryNorm"
                                                    }
                                                ]
                                            },
                                            {
                                                "value": 9.89041,
                                                "description": "fieldWeight in 8931, product of:",
                                                "details": [
                                                    {
                                                        "value": 1,
                                                        "description": "tf(freq=1.0), with freq of:",
                                                        "details": [
                                                            {
                                                                "value": 1,
                                                                "description": "termFreq=1.0"
                                                            }
                                                        ]
                                                    },
                                                    {
                                                        "value": 9.89041,
                                                        "description": "idf(docFreq=1, maxDocs=14524)"
                                                    },
                                                    {
                                                        "value": 1,
                                                        "description": "fieldNorm(doc=8931)"
                                                    }
                                                ]
                                            }
                                        ]
                                    }
                                ]
                            }
                        ]
                    },
                    {
                        "value": 1.795792,
                        "description": "sum of:",
                        "details": [
                            {
                                "value": 1.795792,
                                "description": "weight(lastname:sultXXXX in 8931) [PerFieldSimilarity], result of:",
                                "details": [
                                    {
                                        "value": 1.795792,
                                        "description": "score(doc=8931,freq=1.0 = termFreq=1.0\n), product of:",
                                        "details": [
                                            {
                                                "value": 0.18156901,
                                                "description": "queryWeight, product of:",
                                                "details": [
                                                    {
                                                        "value": 9.89041,
                                                        "description": "idf(docFreq=1, maxDocs=14524)"
                                                    },
                                                    {
                                                        "value": 0.018358087,
                                                        "description": "queryNorm"
                                                    }
                                                ]
                                            },
                                            {
                                                "value": 9.89041,
                                                "description": "fieldWeight in 8931, product of:",
                                                "details": [
                                                    {
                                                        "value": 1,
                                                        "description": "tf(freq=1.0), with freq of:",
                                                        "details": [
                                                            {
                                                                "value": 1,
                                                                "description": "termFreq=1.0"
                                                            }
                                                        ]
                                                    },
                                                    {
                                                        "value": 9.89041,
                                                        "description": "idf(docFreq=1, maxDocs=14524)"
                                                    },
                                                    {
                                                        "value": 1,
                                                        "description": "fieldNorm(doc=8931)"
                                                    }
                                                ]
                                            }
                                        ]
                                    }
                                ]
                            }
                        ]
                    }
                ]
            },
            {
                "value": 0.6666667,
                "description": "coord(2/3)"
            }
        ]
    }
}

我知道should是匹配的,因为没有它们,我得到的第一个结果与它们不同。

我希望我在这种情况下正确使用phrase_prefix。从文档中我并不完全清楚。此页面引用了它们(http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-match-query.html#_match_phrase_prefix),但仅限于常规query,而不是multi_match

0 个答案:

没有答案