当前位置:   article > 正文

3.elasticsearch文档查询dsl_elasticsearch dsl

elasticsearch dsl

【README】

1.本文elasticsearch版本是 7.2.1;

2.文档查询语句叫做 DSL, domain structure language, 领域特定语言;dsl,参见 Query DSL | Elasticsearch Guide [7.2] | Elastic

3.elasticsearch 基于json 提供了完整的查询 DSL 语句(Domain Specific Language-领域特定语言)来定义查询,把查询的dsl看做一种查询的抽象语法树,包含两种类型的查询;

  • 1.叶子查询子句:叶子查询子句在特定字段中寻找特定值,如匹配(match),术语(term)或范围查询(range) ;
  • 2.复合查询子句: 复合查询子句包裹了其他叶子查询或复合查询,并以逻辑方式组合多个查询(如bool,dis_max 查询),或变更他们的行为(如 constant_score 不计算评分);

4.查询子句的行为不同,具体取决于它们是用于查询上下文还是过滤器上下文

  • 查询上下文:若查询条件的字段类型是字符串,则计算文档相关性分数;
  • 过滤器上下文:若查询条件的字段类型是字符串,则不计算文档分数;

5.查询dsl api分类(包括但不限于,本文仅列出常用查询api);

  • match_all,查询所有文档;
  • match,全文检索(若字段是非字符串,则精确匹配,若是字符串类型,则是模糊匹配)
  • match_phrase,短语匹配;
  • multi_match,多字段匹配;
  • bool,组合多个查询子句的复合查询,子句包括 must, must_not, should, filter 等;
  • filter过滤器查询(不计算文档评分);
  • term,术语查询(精确匹配)
  • constant_score,常量分数查询(不计算文档分数);

6.本文es文档数据来源于  content-elasticsearch-deep-dive/accounts.json at master · linuxacademy/content-elasticsearch-deep-dive · GitHubMyles Elastic Certified Engineer Course. Contribute to linuxacademy/content-elasticsearch-deep-dive development by creating an account on GitHub.https://github.com/linuxacademy/content-elasticsearch-deep-dive/blob/master/sample_data/accounts.json,批量导入,参见 2.elasticsearch文档批量操作-bulk api_PacosonSWJTU的博客-CSDN博客

中的  “【2】bulk 批量导入样本数据章节”;

7.elasticsearch查询 dsl api 是否计算文档分数统计表


【1】match_all ,查询所有文档

0)match_all 查询所有文档,给定文档分数为1.0 (不计算文档分数,给定1.0)

1)分页查询银行账户索引文档;

  1. // 【sql】
  2. Select firstname, balance
  3. From bank
  4. Order by balance desc
  5. Limit 5 offset 0/5
  6. // elasticsearch match_all api
  7. Post localhost:9200/bank/_search
  8. {
  9.     "_source":["firstname""balance"]
  10.     ,"query":{
  11.         "match_all":{}
  12.     }
  13.     , "sort":[
  14.         {
  15.             "balance":"desc"
  16.         }
  17.     ]
  18.     , "from":5/0 // 文档偏移量为5 或者 0
  19.     , "size":5 // 每页5个文档
  20. }

【2】match-全文检索

match匹配结果:返回与提供的文本、数字、日期或布尔值匹配的文档。

  • 若匹配的字段类型是字符串,则在匹配之前会对查询条件的字符串进行分词(如hello world 会分词为 hello和 world两个单词);
  • 匹配查询是执行全文搜索的标准查询,包括模糊匹配选项。

【2.1】精确匹配

1)match 匹配非字符串类型字段,就是精确匹配

  • 因为非字符串类型字段的值没有建立倒排索引(分词),值就是它本身;

2)查询余额等于  49568 的客户信息文档

  1. Post localhost:9200/bank/_search
  2. {
  3.     "_source":["firstname""balance"]
  4.     ,"query":{
  5.         "match":{
  6.             "balance":49568
  7.         }
  8.     }   
  9. }
  10. {
  11.     "took"18,
  12.     "timed_out"false,
  13.     "_shards": {
  14.         "total"1,
  15.         "successful"1,
  16.         "skipped"0,
  17.         "failed"0
  18.     },
  19.     "hits": {
  20.         "total": {
  21.             "value"1,
  22.             "relation""eq"
  23.         },
  24.         "max_score"1.0, // 评分默认为1,没有计算文档评分
  25.         "hits": [
  26.             {
  27.                 "_index""bank",
  28.                 "_type""account",
  29.                 "_id""168",
  30.                 "_score"1.0, // 评分默认为1,没有计算文档评分
  31.                 "_source": {
  32.                     "firstname""Carissa",
  33.                     "balance"49568
  34.                 }
  35.             }
  36.         ]
  37.     }
  38. }

【2.2】match-模糊匹配(计算文档评分)

0)match匹配字符串类型字段,就是模糊匹配;

1)查询地址包含 Kings 的银行客户文档

  1. Post localhost:9200/bank/_search
  2. {
  3.     "_source":["firstname""balance","address"]
  4.     ,"query":{
  5.         "match":{
  6.             "address":"Kings"
  7.         }
  8.     }   
  9. }
  10. {
  11.     "took"7,
  12.     "timed_out"false,
  13.     "_shards": {
  14.         "total"1,
  15.         "successful"1,
  16.         "skipped"0,
  17.         "failed"0
  18.     },
  19.     "hits": {
  20.         "total": {
  21.             "value"2,
  22.             "relation""eq"
  23.         },
  24.         "max_score"5.9908285,// 显然计算了文档评分
  25.         "hits": [
  26.             {
  27.                 "_index""bank",
  28.                 "_type""account",
  29.                 "_id""20",
  30.                 "_score"5.9908285,
  31.                 "_source": {
  32.                     "firstname""Elinor",
  33.                     "address""282 Kings Place",
  34.                     "balance"16418
  35.                 }
  36.             },
  37.             {
  38.                 "_index""bank",
  39.                 "_type""account",
  40.                 "_id""722",
  41.                 "_score"5.9908285,
  42.                 "_source": {
  43.                     "firstname""Roberts",
  44.                     "address""305 Kings Hwy",
  45.                     "balance"27256
  46.                 }
  47.             }
  48.         ]
  49.     }
  50. }

【小结】match的字段类型是字符串时 (注意match的字段类型是非字符串,则是精确匹配

  • 全文检索按照评分进行排序;
  • 全文检索会对检索条件进行分词匹配; 

【3】match_phrase 短语匹配 (不分词)

1)match_phrase短语匹配:把需要匹配的值当做一个整体单词(不分词)进行检索;

  • 而match 模糊匹配: 把需要匹配的值先进行分词,然后检索;

2)match 全文检索例子(查询结果有19个文档)

  1. Post localhost:9200/bank/_search
  2. {
  3.     "_source":["firstname""balance","address"]
  4.     ,"query":{
  5.         "match":{
  6.             "address":"mill lane"
  7.         }
  8.     }   
  9. }

【解析】

  • match 全文检索,会把 mill lane 分为2个单词,查询出包含2个单词中的一个即可;

3)match_phrase:短语匹配例子 (查询结果只有1个文档)

  1. Post localhost:9200/bank/_search
  2. {
  3.     "_source":["firstname""balance","address"]
  4.     ,"query":{
  5.         "match_phrase":{
  6.             "address":"mill lane"
  7.         }
  8.     }   
  9. }
  10. {
  11.     "took"2,
  12.     "timed_out"false,
  13.     "_shards": {
  14.         "total"1,
  15.         "successful"1,
  16.         "skipped"0,
  17.         "failed"0
  18.     },
  19.     "hits": {
  20.         "total": {
  21.             "value"1,
  22.             "relation""eq"
  23.         },
  24.         "max_score"9.507477,
  25.         "hits": [
  26.             {
  27.                 "_index""bank",
  28.                 "_type""account",
  29.                 "_id""136",
  30.                 "_score"9.507477,
  31.                 "_source": {
  32.                     "firstname""Winnie",
  33.                     "address""198 Mill Lane",
  34.                     "balance"45801
  35.                 }
  36.             }
  37.         ]
  38.     }
  39. }

【解析】match_phrase:把 mill lane 当做一个整体,不分词,送入es查询包含 mill lane的文档;


【4】multi_match 多字段匹配

1)场景: 查询出 state或address字段包含 mill 的文档;

  1. Post localhost:9200/bank/_search
  2. {
  3.     "_source":["firstname""balance","address","state"]
  4.     ,"query":{
  5.         "multi_match":{
  6.             "query":"mill"
  7.             , "fields":["state""address"]
  8.         }
  9.     }   
  10. }
  11. // 查询结果
  12. {
  13.     "took"2,
  14.     "timed_out"false,
  15.     "_shards": {
  16.         "total"1,
  17.         "successful"1,
  18.         "skipped"0,
  19.         "failed"0
  20.     },
  21.     "hits": {
  22.         "total": {
  23.             "value"4,
  24.             "relation""eq"
  25.         },
  26.         "max_score"5.4032025,
  27.         "hits": [
  28.             {
  29.                 "_index""bank",
  30.                 "_type""account",
  31.                 "_id""970",
  32.                 "_score"5.4032025,
  33.                 "_source": {
  34.                     "firstname""Forbes",
  35.                     "address""990 Mill Road",
  36.                     "balance"19648,
  37.                     "state""AK"
  38.                 }
  39.             },
  40. ......
  41. }

【4.1】多字段匹配给定的分词条件

1)场景: 查询出 state或address字段包含 mill 或 KY的文档;  

  1. {
  2.     "_source":["firstname""balance","address","state"]
  3.     ,"query":{
  4.         "multi_match":{
  5.             "query":"mill KY"
  6.             , "fields":["state""address"]
  7.         }
  8.     }   
  9. }

【5】bool复合查询(组合多个查询条件 )

【5.1】定义

1)bool 用来做复合查询;

  • bool复合查询可以合并任何其他查询语句,包括复合语句;
  • 复合语句之间可以相互嵌套,可以表达非常复杂的逻辑;  

2)bool 复合查询可以包含的查询子句

  • ① must(计算文档分数)
  • ② must_not(不计算文档分数)
  • ③ should(计算文档分数)
  • ④ filter (不计算文档分数)

【5.2】bool复合查询例子

1)场景: 查询gender等于M,state等于KY,且 age不等于28,或者 lastname等于 Hancock的文档;

  • should表示或者,如果匹配,则评分更高;
  1. Post localhost:9200/bank/_search
  2. {
  3.     "query":{
  4.         "bool":{
  5.             "must":[
  6.                 {"match":{"gender":"M"}}
  7.                 ,{"match":{"state":"KY"}}
  8.             ]
  9.             ,"must_not":[
  10.                 {"match":{"age":"28"}}
  11.             ]
  12.             ,"should":[
  13.                 {"match":{"lastname":"Hancock"}}
  14.             ]
  15.         }
  16.     }
  17. }
  18. // 查询结果
  19. {
  20.     "took"8,
  21.     "timed_out"false,
  22.     "_shards": {
  23.         "total"1,
  24.         "successful"1,
  25.         "skipped"0,
  26.         "failed"0
  27.     },
  28.     "hits": {
  29.         "total": {
  30.             "value"6,
  31.             "relation""eq"
  32.         },
  33.         "max_score"11.173532,
  34.         "hits": [
  35.             {
  36.                 "_index""bank",
  37.                 "_type""account",
  38.                 "_id""640",
  39.                 "_score"11.173532, // 计算文档得分
  40.                 "_source": {
  41.                     "account_number"640,
  42.                     "balance"35596,
  43.                     "firstname""Candace",
  44.                     "lastname""Hancock",
  45.                     "age"25,
  46.                     "gender""M",
  47.                     "address""574 Riverdale Avenue",
  48.                     "employer""Animalia",
  49.                     "email""candacehancock@animalia.com",
  50.                     "city""Blandburg",
  51.                     "state""KY"
  52.                 }
  53.             },
  54. ............................

【6】filter过滤器(不计算文档分数)

1)filter 不计算文档分数 ;  

  • Bool复合查询中的must,should,must_not 被称为查询子句;
  • 其中 must或should会计算相关性评分以表示一个文档对查询条件的匹配程度;分数越高,文档就越匹配查询条件;
  • 但 must_not 被当做一个过滤器,过滤器不会计算文档匹配的分数;

【6.1】不用filter过滤器查询例子 (计算评分)

1)不用filter的查询(计算分数)

场景:查询年龄大于等于18,且小于等于30,且address包含mill的文档;

注意: match:{"address":"mill"} 表示的是 address包含mill,并不是address等于mill

  1. Post localhost:9200/bank/_search
  2. {
  3.     "query":{
  4.         "bool":{
  5.             "must":[
  6.                 {
  7.                     "range":{
  8.                         "age":{"gte":18,"lte":30}
  9.                     }
  10.                 }
  11.                 , {
  12.                     "match":{"address":"mill"}
  13.                 }
  14.             ]
  15.         }
  16.     }
  17. }
  18. // 查询结果
  19. {
  20.     "took"2,
  21.     "timed_out"false,
  22.     "_shards": {
  23.         "total"1,
  24.         "successful"1,
  25.         "skipped"0,
  26.         "failed"0
  27.     },
  28.     "hits": {
  29.         "total": {
  30.             "value"1,
  31.             "relation""eq"
  32.         },
  33.         "max_score"6.4032025,
  34.         "hits": [
  35.             {
  36.                 "_index""bank",
  37.                 "_type""account",
  38.                 "_id""970",
  39.                 "_score"6.4032025,// 计算分数
  40.                 "_source": {
  41.                     "account_number"970,
  42.                     "balance"19648,
  43.                     "firstname""Forbes",
  44.                     "lastname""Wallace",
  45.                     "age"28,
  46.                     "gender""M",
  47.                     "address""990 Mill Road",
  48.                     "employer""Pheast",
  49.                     "email""forbeswallace@pheast.com",
  50.                     "city""Lopezo",
  51.                     "state""AK"
  52.                 }
  53.             }
  54.         ]
  55.     }
  56. }

【6.2】用filter过滤器查询(不计算分数)

1)用filter过滤器查询,就不会计算文档的相关性分数;

  • 因为filter不计算分数,filter的查询性能优于 match匹配查询

2)场景:查询年龄大于等于18,且小于等于30,且address包含mill的文档;

查询结果的分数为0.0,显然 filter不会计算分数

  1. Post localhost:9200/bank/_search
  2. {
  3.     "query":{
  4.         "bool":{
  5.             "filter":[
  6.                 {
  7.                     "range":{
  8.                         "age":{"gte":18,"lte":30}
  9.                     }
  10.                 }
  11.                 , {
  12.                     "match":{"address":"mill"}
  13.                 }
  14.             ]
  15.         }
  16.     }
  17. }
  18. {
  19.     "took"2,
  20.     "timed_out"false,
  21.     "_shards": {
  22.         "total"1,
  23.         "successful"1,
  24.         "skipped"0,
  25.         "failed"0
  26.     },
  27.     "hits": {
  28.         "total": {
  29.             "value"1,
  30.             "relation""eq"
  31.         },
  32.         "max_score"0.0,
  33.         "hits": [
  34.             {
  35.                 "_index""bank",
  36.                 "_type""account",
  37.                 "_id""970",
  38.                 "_score"0.0, // 没有计算得分
  39.                 "_source": {
  40.                     "account_number"970,
  41.                     "balance"19648,
  42.                     "firstname""Forbes",
  43.                     "lastname""Wallace",
  44.                     "age"28,
  45.                     "gender""M",
  46.                     "address""990 Mill Road",
  47.                     "employer""Pheast",
  48.                     "email""forbeswallace@pheast.com",
  49.                     "city""Lopezo",
  50.                     "state""AK"
  51.                 }
  52.             }
  53.         ]
  54.     }
  55. }

【6.3】把 filter 作为bool的查询子句

1)场景:查询 gender等于M,且state等于KY,且age不等于28,或者 lastname等于 Hancock,且 age在25到30之间的文档;

  • 其中 must,should子句计算评分, must_not, filter 不计算评分; 
  1. Post localhost:9200/bank/_search
  2. {
  3.     "query":{
  4.         "bool":{
  5.             "must":[
  6.                 {"match":{"gender":"M"}}
  7.                 ,{"match":{"state":"KY"}}
  8.             ]
  9.             ,"must_not":[
  10.                 {"match":{"age":"28"}}
  11.             ]
  12.             ,"should":[
  13.                 {"match":{"lastname":"Hancock"}}
  14.             ]
  15.             , "filter":{
  16.                 "range":{
  17.                     "age":{"gte":"25","lte":"30"}
  18.                 }
  19.             }
  20.         }
  21.     }
  22. }
  23. // 查询结果
  24. {
  25.     "took"4,
  26.     "timed_out"false,
  27.     "_shards": {
  28.         "total"1,
  29.         "successful"1,
  30.         "skipped"0,
  31.         "failed"0
  32.     },
  33.     "hits": {
  34.         "total": {
  35.             "value"1,
  36.             "relation""eq"
  37.         },
  38.         "max_score"11.173532,
  39.         "hits": [
  40.             {
  41.                 "_index""bank",
  42.                 "_type""account",
  43.                 "_id""640",
  44.                 "_score"11.173532,
  45.                 "_source": {
  46.                     "account_number"640,
  47.                     "balance"35596,
  48.                     "firstname""Candace",
  49.                     "lastname""Hancock",
  50.                     "age"25,
  51.                     "gender""M",
  52.                     "address""574 Riverdale Avenue",
  53.                     "employer""Animalia",
  54.                     "email""candacehancock@animalia.com",
  55.                     "city""Blandburg",
  56.                     "state""KY"
  57.                 }
  58.             }
  59.         ]
  60.     }
  61. }

2)如何使得上述bool查询中的must,should 不计算分数呢 ?将其嵌套在 filter 里面,如下:

  1. post localhost:9200/bank/_search
  2. {
  3. "query":{
  4. "bool":{
  5. "filter":{
  6. "bool":{
  7. "must":[
  8. {"match":{"gender":"M"}}
  9. ,{"match":{"state":"KY"}}
  10. ]
  11. ,"must_not":[
  12. {"match":{"age":"28"}}
  13. ]
  14. ,"should":[
  15. {"match":{"lastname":"Hancock"}}
  16. ]
  17. , "filter":{
  18. "range":{
  19. "age":{"gte":"25","lte":"30"}
  20. }
  21. }
  22. }
  23. }
  24. }
  25. }
  26. }
  27. // 查询结果
  28. {
  29. "took": 368,
  30. "timed_out": false,
  31. "_shards": {
  32. "total": 1,
  33. "successful": 1,
  34. "skipped": 0,
  35. "failed": 0
  36. },
  37. "hits": {
  38. "total": {
  39. "value": 1,
  40. "relation": "eq"
  41. },
  42. "max_score": 0.0,
  43. "hits": [
  44. {
  45. "_index": "bank",
  46. "_type": "account",
  47. "_id": "640",
  48. "_score": 0.0, // 显然没有计算文档分数
  49. "_source": {
  50. "account_number": 640,
  51. "balance": 35596,
  52. "firstname": "Candace",
  53. "lastname": "Hancock",
  54. "age": 25,
  55. "gender": "M",
  56. "address": "574 Riverdale Avenue",
  57. "employer": "Animalia",
  58. "email": "candacehancock@animalia.com",
  59. "city": "Blandburg",
  60. "state": "KY"
  61. }
  62. }
  63. ]
  64. }
  65. }

【7】term查询(术语查询),精确匹配

1)定义:

  • term查询返回给定字段包含精确值的文档;

2)注意:

  • ① 避免对 text 字段进行term查询;
  • ② 默认情况下,Elasticsearch 会在分析过程中更改文本字段的值(分词)。 这会使查找文本字段值的精确匹配变得困难。
  • ③ 要查询 text字段,使用match(模糊查询)

3)term 与 match 区别:

  • ① term: 精确查询(不分词);
  • ② match: 模糊查询(查询字段的类型是字符串,要分词);

【7.1】term查询例子

1)场景1:查询 address 等于 574 Riverdale Avenue 的文档 ;
es文档中的address被分词了,而term查询对 574 Riverdale Avenue 进行精确查询(不分词),所以查无记录。

  1. {
  2.     "query":{
  3.        "term":{
  4.            "address":"574 Riverdale Avenue"
  5.        }
  6.     }
  7. }
  8. // 为空。

2)场景2:查询 address.keyword 等于 574 Riverdale Avenue 的文档 (查询 address不分词时 等于 574 Riverdale Avenue  的文档 )

  1. {
  2.     "query":{
  3.        "term":{
  4.            "address.keyword":"574 Riverdale Avenue" // 这里匹配的是 address的keyword属性
  5.        }
  6.     }
  7. }
  8. {
  9.     "took"1,
  10.     "timed_out"false,
  11.     "_shards": {
  12.         "total"1,
  13.         "successful"1,
  14.         "skipped"0,
  15.         "failed"0
  16.     },
  17.     "hits": {
  18.         "total": {
  19.             "value"1,
  20.             "relation""eq"
  21.         },
  22.         "max_score"6.5032897,
  23.         "hits": [
  24.             {
  25.                 "_index""bank",
  26.                 "_type""account",
  27.                 "_id""640",
  28.                 "_score"6.5032897,// 显然 term 要评分
  29.                 "_source": {
  30.                     "account_number"640,
  31.                     "balance"35596,
  32.                     "firstname""Candace",
  33.                     "lastname""Hancock",
  34.                     "age"25,
  35.                     "gender""M",
  36.                     "address""574 Riverdale Avenue",
  37.                     "employer""Animalia",
  38.                     "email""candacehancock@animalia.com",
  39.                     "city""Blandburg",
  40.                     "state""KY"
  41.                 }
  42.             }
  43.         ]
  44.     }
  45. }

【结果分析】

  • 显然term精确匹配会计算评分,其经常嵌套在 filter里面,以不计算评分

【7.2】address.keyword 与 match_phrase 区别

1)address.keyword 查无记录;因为是精确匹配(不分词);

场景:查询地址等于 574 Riverdale 的文档;

  1. {
  2.     "query":{
  3.        "term":{
  4.            "address.keyword":"574 Riverdale"
  5.        }
  6.     }
  7. }
  8. // 查无记录

2)match_phrase 是部分匹配,包含 574 Riverdale  即可(有值)

  1. {
  2.     "query":{
  3.        "match_phrase":{
  4.            "address":"574 Riverdale"
  5.        }
  6.     }
  7. }
  8. // 查询结果
  9. {
  10.     "took"1,
  11.     "timed_out"false,
  12.     "_shards": {
  13.         "total"1,
  14.         "successful"1,
  15.         "skipped"0,
  16.         "failed"0
  17.     },
  18.     "hits": {
  19.         "total": {
  20.             "value"1,
  21.             "relation""eq"
  22.         },
  23.         "max_score"12.492344,
  24.         "hits": [
  25.             {
  26.                 "_index""bank",
  27.                 "_type""account",
  28.                 "_id""640",
  29.                 "_score"12.492344,
  30.                 "_source": {
  31.                     "account_number"640,
  32.                     "balance"35596,
  33.                     "firstname""Candace",
  34.                     "lastname""Hancock",
  35.                     "age"25,
  36.                     "gender""M",
  37.                     "address""574 Riverdale Avenue",
  38.                     "employer""Animalia",
  39.                     "email""candacehancock@animalia.com",
  40.                     "city""Blandburg",
  41.                     "state""KY"
  42.                 }
  43.             }
  44.         ]
  45.     }
  46. }

【小结】

  • 若是查询非 text字段,则使用term做精确查询;
  • 若是查询 text字段,则使用 match来全文检索;
  • 若使用match做精确匹配,则使用 field.keyword 进行;
  • 若是查询 text字段的部分匹配(短语匹配,不对字符串不分词),则使用 match_phrase ;

【8】constant_socre 常量分数查询

1)constant_score 不计算分数;

2)constant_score 参数有2个:filter 和 boost

  • filter:必须有;filter查询不会计算相关性分数;为了加速性能,elasticsearch自动缓存频繁使用的 filter查询;
  • boost:可选,浮点型,用于指定每个文档的分数,默认为1.0;

场景:查询年龄在大于等于25,且小于等于30的文档;

  1. post localhost:9200/bank/_search
  2. {
  3. "query":{
  4. "constant_score":{
  5. "filter":{
  6. "range":{
  7. "age":{"gte":"25","lte":"30"}
  8. }
  9. }
  10. }
  11. }
  12. }
  13. // 查询结果
  14. {
  15. "took": 4,
  16. "timed_out": false,
  17. "_shards": {
  18. "total": 1,
  19. "successful": 1,
  20. "skipped": 0,
  21. "failed": 0
  22. },
  23. "hits": {
  24. "total": {
  25. "value": 273,
  26. "relation": "eq"
  27. },
  28. "max_score": 1.0,
  29. "hits": [
  30. {
  31. "_index": "bank",
  32. "_type": "account",
  33. "_id": "13",
  34. "_score": 1.0, // 显然,文档分数默认为1.0
  35. "_source": {
  36. "account_number": 13,
  37. "balance": 32838,
  38. "firstname": "Nanette",
  39. "lastname": "Bates",
  40. "age": 28,
  41. "gender": "F",
  42. "address": "789 Madison Street",
  43. "employer": "Quility",
  44. "email": "nanettebates@quility.com",
  45. "city": "Nogal",
  46. "state": "VA"
  47. }
  48. },
  49. ......
  50. }

参考自: Constant score query | Elasticsearch Guide [7.2] | Elastichttps://www.elastic.co/guide/en/elasticsearch/reference/7.2/query-dsl-constant-score-query.html

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Gausst松鼠会/article/detail/547379
推荐阅读
相关标签
  

闽ICP备14008679号