![](/img/trans.png)
[英]Matching multiple fields with Firebase Flashlight and Elastic Search
[英]elastic search multi-fields matching problem
我有一個彈性搜索查詢。 我正在寫這樣的查詢。
$params = [
'index' => config('elasticsearch.index'),
'type' => $this->type,
'body' => [
'query' => [
'multi_match' => [
'query' => 'newyork john',
'type'=>'cross_fields',
'fields'=>['user','surname','location'],
'tie_breaker'=>'0.3',
'minimum_should_match'=>'10%',
]
]
]
];
例如,此查詢返回以下結果。
id=>1
score => 0.9808292
user => nja
surname => foo
'location'=> newyork
//1 field matching
id=>2
score => 0.87546873
user => alex
surname => stephen
'location'=> newyork
//1 field matching
id=>3
score => 0.18232156,
user => alex
surname => john
'location'=> newyork
//2 field matching
但如果還有多少字段匹配,我想在頂部看到它。這個查詢不這樣做。 2 字段的匹配數據在底部。我實際上想在頂部看到它。
我怎樣才能做到這一點?
您必須使用most_fields
類型而不是cross_fields
:
您可以在此處查看文檔: https : //www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-multi-match-query.html#multi-match-types
most_fields
查找匹配任何字段並組合每個字段的 _score 的文檔。 請參閱 most_fields。
cross_fields
使用相同的分析器將字段視為一個大字段。 在任何字段中查找每個單詞。 見cross_fields。
most_fields
類型將添加匹配字段的分數,從而顯着提升在不同字段中匹配查詢的文檔。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.