当前位置: 首页 > news >正文

推荐大良网站建设目录浏览的网站

推荐大良网站建设,目录浏览的网站,网站建设哪家好首推万维科技,织梦配置手机网站query_string查询介绍 1 概述2 基本概念3 数据准备4 query_string查询示例4.1 基本查询4.2 复杂查询解析4.3 高级过滤解析4.4 模糊查询解析4.5 高亮查询解析4.6 分页查询解析 5 总结 大家好#xff0c;我是欧阳方超#xff0c;可以我的公众号“欧阳方超”#xff0c;后续内容… query_string查询介绍 1 概述2 基本概念3 数据准备4 query_string查询示例4.1 基本查询4.2 复杂查询解析4.3 高级过滤解析4.4 模糊查询解析4.5 高亮查询解析4.6 分页查询解析 5 总结 大家好我是欧阳方超可以我的公众号“欧阳方超”后续内容将在公众号首发。 1 概述 Elasticsearch中的query_string查询是一种强大的工具允许用户使用复杂的查询语法来搜索文档。它支持多个字段、布尔逻辑、通配符等功能适合于需要灵活搜索的场景。本文将结合示例详细讲解query_string的用法。 2 基本概念 query_stirng查询使用一种严格的语法来解析用户输入的查询字符串。允许用户使用简洁的字符串实现复杂的查询逻辑它可以分割查询字符串并根据操作符如and、or、not分析每个部分从而返回匹配的文档。 3 数据准备 创建一个存储博客信息的索引并插入一些数据以便后续的查询。 {settings: {number_of_shards: 1,number_of_replicas: 1},mappings: {properties: {title: {type: text},content: {type: text},tags: {type: keyword},author: {type: keyword},publish_date: {type: date,format: yyyy-MM-dd},views: {type: long},status: {type: keyword}}} }插入数据准备 {index:{_id:1}} {title:Getting Started with Elasticsearch,content:Elasticsearch is a powerful search and analytics engine. It provides a distributed, multitenant-capable full-text search engine.,tags:[elasticsearch,guide,search],author:John Doe,publish_date:2023-01-15,views:1000,status:published} {index:{_id:2}} {title:Advanced Elasticsearch Query Guide,content:Learn about complex queries in Elasticsearch including query_string, bool queries and aggregations.,tags:[elasticsearch,advanced,query],author:Jane Smith,publish_date:2023-02-20,views:800,status:published} {index:{_id:3}} {title:Elasticsearch vs Solr Comparison,content:A detailed comparison between Elasticsearch and Solr. Both are powerful search engines built on Apache Lucene.,tags:[elasticsearch,solr,comparison],author:John Doe,publish_date:2023-03-10,views:1200,status:published} {index:{_id:4}} {title:Mastering Kibana Dashboards,content:Create powerful visualizations and dashboards using Kibana with Elasticsearch data.,tags:[kibana,elasticsearch,visualization],author:Alice Johnson,publish_date:2023-04-05,views:600,status:draft} {index:{_id:5}} {title:Elasticsearch Security Best Practices,content:Learn about securing your Elasticsearch cluster, including authentication, authorization, and encryption.,tags:[elasticsearch,security,best practices],author:Bob Wilson,publish_date:2023-05-01,views:1500,status:published}4 query_string查询示例 4.1 基本查询 简单查询 下面的查询将查询content字段包含powerful字符串的文档并将其返回。 {query: {query_string: {default_field:content,query:powerful}} }多字段查询 下面的多字段查询的查询逻辑为 在title和content字段中搜索同时包含elasticsearch和security的文档注意只要在两个字段中能匹配到elasticsearch和security即可不要求在这两个字段的每个字段中都能匹配到elasticsearch和security。and操作符要求两个条件都满足 {query: {query_string: {fields:[title,content],query:elasticsearch AND security}} }只有id5的文档能被查出来因为它的title包含security且content包含elasticsearch。 4.2 复杂查询解析 组合条件查询 {query: {query_string: {fields:[title,content],query:(elasticsearch OR solr) AND (guide OR comparison)}} }上面的DSL逻辑为 在title和content字段中搜索文档必须满足 包含elasticsearch或solr中的至少一个AND 包含guide或comparison中的至少一个 会查询出两个文档 id2 的文档包含elasticsearch和guideid3 的文档包含elasticsearch/solr和comparison 范围查询 {query: {query_string: {query:elasticsearch AND publish_date:[2023-01-01 TO 2023-03-31] AND views:1000}} }上面DSL查询逻辑为 搜索满足以下所有条件的文档 包含elasticsearch发布日期在2023-01-01到2023-03-31之间浏览量大于1000 只有id3的文档可以被查询到。 4.3 高级过滤解析 {query: {query_string: {query: status:published AND author:\John Doe\ AND (title:elasticsearch OR content:elasticsearch)}} }搜索满足以下所有条件的文档 状态为published作者为John Doe标题或内容中包含elasticsearch 最终文档1和3符合条件被查询到。 以下是查询结果 {took: 8,timed_out: false,_shards: {total: 1,successful: 1,skipped: 0,failed: 0},hits: {total: {value: 2,relation: eq},max_score: 1.525382,hits: [{_index: blog_index,_id: 3,_score: 1.525382,_source: {title: Elasticsearch vs Solr Comparison,content: A detailed comparison between Elasticsearch and Solr. Both are powerful search engines built on Apache Lucene.,tags: [elasticsearch,solr,comparison],author: John Doe,publish_date: 2023-03-10,views: 1200,status: published}},{_index: blog_index,_id: 1,_score: 1.5210661,_source: {title: Getting Started with Elasticsearch,content: Elasticsearch is a powerful search and analytics engine. It provides a distributed, multitenant-capable full-text search engine.,tags: [elasticsearch,guide,search],author: John Doe,publish_date: 2023-01-15,views: 1000,status: published}}]} }4.4 模糊查询解析 {query: {query_string: {query: elasticsearch AND status:published}},size : 0,aggs: {authors: {terms: {field: author}},avg_views: {avg: {field: views}}} }这是一个用于搜索和聚合数据的请求稍微复杂一些下面详细介绍下。 查询部分 query这是整个查询的主体指定了要执行的搜索操作。query_string这部分使用了查询字符串语法允许通过简单的文本表达式来构建复杂的查询。 query这是的值是elasticsearch AND status:published意味着要搜索包含elasticsearch这个词并且其status字段为published的文档AND确保两个条件都满足。 聚合部分 aggs这个部分用于定义聚合操作可以对查询结果进行统计和分析。 作者聚合 authors这是一个自定义的聚合名称用于统计不同作者的文档数量。 terms指定使用分组聚合terms是桶聚合的一种其作用类似于SQL的group by根据字段分组相同字段值的文档分为一组。 “field”author表示按照author字段的值进行分组结果将返回每个作者及其对应的文档计数。 平均浏览量聚合 avg_views这是另一个自定义聚合名称用于计算文档的平均浏览量。 avg指定平均值聚合。 “field”: “views表示计算views字段的平均值。这将返回所有匹配文档中views字段的平均值。 注意上面的DSL中设置了这将仅返回聚合查询结果不返回普通query查询结果即hits”: []。以下是查询结果 {took: 4,timed_out: false,_shards: {total: 1,successful: 1,skipped: 0,failed: 0},hits: {total: {value: 4,relation: eq},max_score: null,hits: []},aggregations: {avg_views: {value: 1125},authors: {doc_count_error_upper_bound: 0,sum_other_doc_count: 0,buckets: [{key: John Doe,doc_count: 2},{key: Bob Wilson,doc_count: 1},{key: Jane Smith,doc_count: 1}]}} }4.5 高亮查询解析 {query: {query_string: {query: elasticsearch security}},highlight: {fields: {title: {},content: {}}} }上面的DSL分查询和高亮两部分下面详细解释一下。 查询部分 query这是整个查询的主体定义了要执行的搜索操作。query_string这个部分使用了查询字符串语法运行通过简单的文本表达式构建复杂的查询。 query这里的值是elasticsearch security这意味着要查找包含elasticsearch和security这两个词的文档。默认情况下elasticsearch将这些词视为单独的词进行处理并使用OR逻辑运算符连接它们这意味着只要文档中包含其中一个词就会被匹配。fields这个参数指定了要搜索的字段这个例子中搜索将在title和content字段中进行只有这两个字段中的内容会被考虑用于匹配查询。 高亮部分 highlight这部分用于定义特殊标记的设置每个文档中匹配的词会被特殊标记默认用标签包围以便在搜索结果中突出显示匹配的内容。 fields指定需要高亮显示的字段上例中指定了title和content字段这意味着当搜索结果返回时如果这些字段中的内容与查询匹配它们将被高亮显示以便用户能够快速识别相关信息。 下面是查询结果 {took: 5,timed_out: false,_shards: {total: 1,successful: 1,skipped: 0,failed: 0},hits: {total: {value: 5,relation: eq},max_score: 1.6386936,hits: [{_index: blog_index,_id: 5,_score: 1.6386936,_source: {title: Elasticsearch Security Best Practices,content: Learn about securing your Elasticsearch cluster, including authentication, authorization, and encryption.,tags: [elasticsearch,security,best practices],author: Bob Wilson,publish_date: 2023-05-01,views: 1500,status: published},highlight: {title: [emElasticsearch/em emSecurity/em Best Practices],content: [Learn about securing your emElasticsearch/em cluster, including authentication, authorization, and encryption]}},{_index: blog_index,_id: 1,_score: 0.28161854,_source: {title: Getting Started with Elasticsearch,content: Elasticsearch is a powerful search and analytics engine. It provides a distributed, multitenant-capable full-text search engine.,tags: [elasticsearch,guide,search],author: John Doe,publish_date: 2023-01-15,views: 1000,status: published},highlight: {title: [Getting Started with emElasticsearch/em],content: [emElasticsearch/em is a powerful search and analytics engine.]}},{_index: blog_index,_id: 2,_score: 0.28161854,_source: {title: Advanced Elasticsearch Query Guide,content: Learn about complex queries in Elasticsearch including query_string, bool queries and aggregations.,tags: [elasticsearch,advanced,query],author: Jane Smith,publish_date: 2023-02-20,views: 800,status: published},highlight: {title: [Advanced emElasticsearch/em Query Guide],content: [Learn about complex queries in emElasticsearch/em including query_string, bool queries and aggregations.]}},{_index: blog_index,_id: 3,_score: 0.28161854,_source: {title: Elasticsearch vs Solr Comparison,content: A detailed comparison between Elasticsearch and Solr. Both are powerful search engines built on Apache Lucene.,tags: [elasticsearch,solr,comparison],author: John Doe,publish_date: 2023-03-10,views: 1200,status: published},highlight: {title: [emElasticsearch/em vs Solr Comparison],content: [A detailed comparison between emElasticsearch/em and Solr.]}},{_index: blog_index,_id: 4,_score: 0.09708915,_source: {title: Mastering Kibana Dashboards,content: Create powerful visualizations and dashboards using Kibana with Elasticsearch data.,tags: [kibana,elasticsearch,visualization],author: Alice Johnson,publish_date: 2023-04-05,views: 600,status: draft},highlight: {content: [Create powerful visualizations and dashboards using Kibana with emElasticsearch/em data.]}}]} }4.6 分页查询解析 下面是一个使用查询字符串语法进行分页查询的示例 {query: {query_string: {query: elasticsearch security}},from:0,size:4,sort:[{views:desc}] }有三部分组成查询部分、分页控制部分和排序部分。 查询部分字符串查询语法。分页控制部分 “from”: 0这个参数指定从结果集中的第0个文档开始返回即从第一条记录开始。用于实现分页功能。“size”: 2指定要返回的文档数量。在这个例子中最多返回2条匹配的文档。这与from参数结合使用你可以实现更灵活的分页。 排序部分 sort用于定义如何对搜索结果进行排序。{ “views”: “desc” }表示根据views字段进行降序排序。 下面是返回值 {took: 6,timed_out: false,_shards: {total: 1,successful: 1,skipped: 0,failed: 0},hits: {total: {value: 5,relation: eq},max_score: null,hits: [{_index: blog_index,_id: 5,_score: null,_source: {title: Elasticsearch Security Best Practices,content: Learn about securing your Elasticsearch cluster, including authentication, authorization, and encryption.,tags: [elasticsearch,security,best practices],author: Bob Wilson,publish_date: 2023-05-01,views: 1500,status: published},sort: [1500]},{_index: blog_index,_id: 3,_score: null,_source: {title: Elasticsearch vs Solr Comparison,content: A detailed comparison between Elasticsearch and Solr. Both are powerful search engines built on Apache Lucene.,tags: [elasticsearch,solr,comparison],author: John Doe,publish_date: 2023-03-10,views: 1200,status: published},sort: [1200]}]} }5 总结 介绍了查询字符串query_string语法并结合一些高级查询展示了查询字符串语法的使用。如果你觉得“查询字符串”这种叫法有些奇怪大可不必因为这完全是安装query_string译过来的。 我是欧阳方超把事情做好了自然就有兴趣了如果你喜欢我的文章欢迎点赞、转发、评论加关注。我们下次见。
http://www.hkea.cn/news/14399518/

相关文章:

  • 黔东南州两学一做教育网站房天下网站建设
  • 饮食类网站本机做wordpress乱码
  • 网站实现隶书繁体搜索引擎网站大全
  • 音乐类网站建设选题背景导航网站开发工具
  • asp技校网站网上挣钱
  • 网站模板免费推荐涿州网站建设涿州
  • 商务网站内容维护和管理的范围wordpress建手机站
  • 东莞网络推广平符合seo的网站
  • 太原网站备案现场核验模板网站也需要服务器吗
  • dedecms网站地图模板怎么网站建设案例价格
  • 网站红色搭配wordpress 获取某个栏目名称
  • 小米的网站是哪个公司做的关于网页制作
  • 如何做网站专题四面山网站建设
  • 如何做电商网站首页湖南网站搜索排名优化电话
  • 网站后台管理系统内容wordpress去
  • 办公类网站开发背景湖南省郴州市宜章县
  • 做空闲时间的网站网站建设的现状分析
  • 西安网站建设sxyunp2p网站建设的步骤过程
  • 做拍卖网站wordpress搜索调用
  • 网站开发是什么部门搜索引擎优化的目的是什么
  • 数码公司网站建设调查微信生活门户网站源码
  • 深圳做网站 汉狮网络黑龙江省华龙建设有限公司网站
  • 起飞页自助建站平台的特点网站以前在百度能搜索不到
  • 老师用什么网站做ppt获取网站访客qq
  • .net 购物网站开发源代码外国s网站建设
  • 武进网站建设公司深圳网站建设怎样快速
  • 济阳网站建设企业网站设计与管理
  • 做的网站在不同浏览器保险网站哪个好
  • 网站规划模板谷歌做公司网站需要多少钱
  • 网站开发设计图psd怎样做读书会网站