版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/D_iRe_Wol_F/article/details/83273951
15.记录------查询体
使用GET进行查询,可以带入查询参数.
curl -XGET http://172.16.150.149:29200/facebook,twitter/_search?pretty -d '
{"from":5,"size":3}
'
{
"took" : 1,
"timed_out" : false,
"_shards" : {
"total" : 4,
"successful" : 4,
"failed" : 0
},
"hits" : {
"total" : 8,
"max_score" : 1.0,
"hits" : [ {
"_index" : "facebook",
"_type" : "blog",
"_id" : "AWZ668ZcHFL4sAFl7IMI",
"_score" : 1.0,
"_source" : {
"title" : "website",
"text" : "blog is making",
"date" : "2018/1016"
}
}...
16.记录------匹配前缀解析查询
给定一个首字母,进行匹配.
-XGET http://172.16.150.149:29200/facebook,twitter/_search?pretty -d '
{"query":{
"match_phrase_prefix":{
"text":"blog i"
}}}'
{
"took" : 1,
"timed_out" : false,
"_shards" : {
"total" : 4,
"successful" : 4,
"failed" : 0
},
"hits" : {
"total" : 3,
"max_score" : 1.0,
"hits" : [ {
"_index" : "facebook",
"_type" : "blog",
"_id" : "AWZ67I_dHFL4sAFl7IMJ",
"_score" : 1.0,
"_source" : {
"title" : "website",
"text" : "blog is making",
"date" : "2018/1016"
}
...
官方强烈推荐再设置match_phrase_prefix
来设置后续匹配的个数.
curl -XGET http://172.16.150.149:29200/facebook,twitter/_search?pretty -d '
{"query":{
"match_phrase_prefix":{
"text":"blog i"
}}}'
{
"took" : 1,
"timed_out" : false,
"_shards" : {
"total" : 4,
"successful" : 4,
"failed" : 0
},
"hits" : {
"total" : 3,
"max_score" : 1.0,
"hits" : [ {
"_index" : "facebook",
"_type" : "blog",
"_id" : "AWZ67I_dHFL4sAFl7IMJ",
"_score" : 1.0,
"_source" : {
"title" : "website",
"text" : "blog is making",
"date" : "2018/1016"
}
...
17.记录------多匹配查询与_score的进一步了解
curl -XGET http://172.16.150.149:29200/facebook,twitter/_search?pretty -d '
{"query":{
"multi_match":{
"query":"blog is ",
"fields":["title","text"]}}}'
{
"took" : 1,
"timed_out" : false,
"_shards" : {
"total" : 4,
"successful" : 4,
"failed" : 0
},
"hits" : {
"total" : 4,
"max_score" : 0.41762865,
"hits" : [ {
"_index" : "facebook",
"_type" : "blog",
"_id" : "AWZ67I_dHFL4sAFl7IMJ",
"_score" : 0.41762865,
"_source" : {
"title" : "website",
"text" : "blog is making",
"date" : "2018/1016"
}
...
对_score
字段的进一步了解
_score
字段代表着被查询的文章与查询的相关性程度,分越高,自然相关度就越高.
查询结果,往往都按照_score
进行降序显示.
es的评分机制,是建立于lucene的评分基础之上,并且不限于其评分机制.
lucene评分机制
TF/IDF(词频/逆文档频率)算法
其计算文档得分需要考虑若干的影响因素
文档权重(document boost)
字段权重(field boost)
协调因子(coord)
逆文档频率(inverse document frequency)
长度范数(length norm)
词频
查询函数(query norm)
参考详见还包括了Lucene默认与实际评分公式