zoukankan      html  css  js  c++  java
  • ElasticSearch 查询

    公号:码农充电站pro
    主页:https://codeshellme.github.io

    ES 中的查询 API 有两种:

    • URI Search:HTTP GET 请求的方式。
    • Request Body Search:基于 Json 数据格式的 DSL(Query Domain Specific Language)。

    1,指定查询范围

    通过 URI 可以指定在哪些索引中进行查询,有下面几种格式:

    • /_search:在所有的索引中进行搜索。
    • /index_name/_search:在 index_name 索引中进行搜索。
    • /index1,index2/_search:在 index1index2 索引中进行搜索。
    • /index*/_search:在所有的以 index 为前缀的索引中进行搜索。

    2,URI 查询

    URI 查询使用 HTTP GET 请求的方式,使用 q 指定查询的内容,格式如下:

    curl -XGET http://localhost:9200/index_name/_search?q=key:val
    

    简写为:

    GET /index_name/_search?q=key:val
    

    其表示的含义是:在 index_name 索引中的所有文档中,查询 key 字段的值为 val 的内容。

    3,Request Body 查询

    Request Body 查询可以使用 GET 或 POST 方式,格式如下:

    curl -XGET/POST http://localhost:9200/index_name/_search -H 'Content-Type: application/json' -d'
    {
     "query": {
     "match_all":{}
     }
    }'
    

    简写为:

    POST index_name/_search
    {
    	"query": {
    		"match_all": {}
    	}
    }
    

    4,ES 查询的响应内容

    如果查询成功,会返回如下格式的内容:

    在这里插入图片描述

    返回的结果集会以 _score 评分进行排序,_score 评分指的是查询的相关性。

    5,相关性指标

    搜索的相关性有 3 种衡量指标:

    • 查准率:尽可能返回较少的无关文档。
    • 查全率:尽可能返回较多的相关文档。
    • 结果排名:查询结果排名是否准确。

    在 ES 中可以通过调整查询的参数来改善搜素的查准率和查全率。

    (本节完。)


    推荐阅读:

    ElasticSearch 入门简介

    [ElasticSearch 安装与运行](https://www.cnblogs.com/codeshell/p/14371473.html

    Kibana,Logstash 和 Cerebro 的安装运行

    ElasticSearch 搜索引擎概念简介

    ElasticSearch 分词器


    欢迎关注作者公众号,获取更多技术干货。

    码农充电站pro

  • 相关阅读:
    Linux开机流程【原创】
    Linux下无需按下回车(无阻塞)读取输入键值
    Sql Server 列转行 Pivot使用
    mysql
    mysql
    mysql
    CI
    mysql
    Snagit: Scrolling is not working
    Something about SnagIt
  • 原文地址:https://www.cnblogs.com/codeshell/p/14389415.html
Copyright © 2011-2022 走看看