Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/search/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在elasticsearch中使用空格搜索名称(文本)_Search_<img Src="//i.stack.imgur.com/RUiNP.png" Height="16" Width="18" Alt="" Class="sponsor Tag Img">elasticsearch_Tokenize_Analyzer - Fatal编程技术网 elasticsearch,tokenize,analyzer,Search,elasticsearch,Tokenize,Analyzer" /> elasticsearch,tokenize,analyzer,Search,elasticsearch,Tokenize,Analyzer" />

在elasticsearch中使用空格搜索名称(文本)

在elasticsearch中使用空格搜索名称(文本),search,elasticsearch,tokenize,analyzer,Search,elasticsearch,Tokenize,Analyzer,搜索包含空格的名称(文本),给我造成问题, 我有类似的映射 "{"user":{"properties":{"name":{"type":"string"}}}}" 理想情况下,它应该返回什么,并对结果进行如下排序 1) Bring on top names that exact match the search term (highest score) 2) Names that starts with the search term (high score) 3) Names that c

搜索包含空格的名称(文本),给我造成问题, 我有类似的映射

"{"user":{"properties":{"name":{"type":"string"}}}}"
理想情况下,它应该返回什么,并对结果进行如下排序

1) Bring on top names that exact match the search term (highest score)
2) Names that starts with the search term (high score)
3) Names that contains the exact search term as substring (medium score)
4) Names that contains any of the search term token  (lowest score)
范例 用于elasticsearch中的以下名称

Maaz Tariq
Ahmed Maaz Tariq
Maaz Sheeba
Maaz Bin Tariq
Sana Tariq
Maaz Tariq Ahmed
搜索“Maaz Tariq”,结果应按以下顺序排列

Maaz Tariq (highest score)
Maaz Tariq Ahmed (high score)
Ahmed Maaz Tariq (medium score)
Maaz Bin Tariq  (lowest score)
Maaz Sheeba (lowest score)
Sana Tariq (lowest score)
有人能告诉我如何使用哪些分析仪吗?以及如何对名称的搜索结果进行排序?

您可以使用、a和来解决此问题

映射:

{
    "mappings" : {
        "user" : {        
            "properties" : {
                "name": {
                    "type": "multi_field",
                    "fields": {
                        "name": { "type" : "string", "index": "analyzed" },
                        "exact": { "type" : "string", "index": "not_analyzed" }
                    }
                }
            }
        }
    }
}
查询:

{
    "query": {
        "bool": {
            "must": [
                {
                    "match": {
                        "name": "Maaz Tariq"
                    }
                }
            ],
            "should": [
                {
                    "custom_boost_factor": {
                        "query": {
                            "term": {
                                "name.exact": "Maaz Tariq"
                            }
                        },
                        "boost_factor": 15
                    }
                },
                {
                    "custom_boost_factor": {
                        "query": {
                            "prefix": {
                                "name.exact": "Maaz Tariq"
                            }
                        },
                        "boost_factor": 10
                    }
                },
                {
                    "custom_boost_factor": {
                        "query": {
                            "match_phrase": {
                                "name": {
                                    "query": "Maaz Tariq",
                                    "slop": 0
                                }
                            }
                        },
                        "boost_factor": 5
                    }
                }
            ]
        }
    }
}
编辑:

正如javanna所指出的那样,
定制的增强因子是不需要的

不带
自定义\u增压系数的查询

{
    "query": {
        "bool": {
            "must": [
                {
                    "match": {
                        "name": "Maaz Tariq"
                    }
                }
            ],
            "should": [
                {
                    "term": {
                        "name.exact": {
                            "value": "Maaz Tariq",
                            "boost": 15
                        }
                    }
                },
                {
                    "prefix": {
                        "name.exact": {
                            "value": "Maaz Tariq",
                            "boost": 10
                        }
                    }
                },
                {
                    "match_phrase": {
                        "name": {
                            "query": "Maaz Tariq",
                            "slop": 0,
                            "boost": 5
                        }
                    }
                }
            ]
        }
    }
}

对于JavaAPI,当使用空格查询精确字符串时

CLIENT.prepareSearch(index)
    .setQuery(QueryBuilders.queryStringQuery(wordString)
    .field(fieldName));

在许多其他查询中,结果一无所获,从Elasticsearch 1.0:

"title": {
    "type": "multi_field",
    "fields": {
        "title": { "type": "string" },
        "raw":   { "type": "string", "index": "not_analyzed" }
    }
}
成为:

"title": {
    "type": "string",
    "fields": {
        "raw":   { "type": "string", "index": "not_analyzed" }
    }
}

我更喜欢基于过滤器的解决方案,但我找不到适合3的过滤器。要求。您只需对此进行短语查询即可。另外,我不明白为什么需要自定义的系数查询。您不能使用
boost
选项为不同的查询赋予不同的权重吗?
boost
should
子查询中是不允许的!?(至少我不知道这句话的语法。)如果没有
span_near
查询和
match_短语
查询,短语查询过滤器是如何工作的?据我记忆所及,每个查询都支持boost。事实上,短语查询就是你用match_短语所做的,你没有意识到!我试过了。如果我在子查询中添加一个
boost
,它将变得无效。