ElasticSearch使用教程四(ElasticSearch查询详解)
发布日期:2021-05-17 22:23:15 浏览次数:26 分类:精选文章

本文共 1465 字,大约阅读时间需要 4 分钟。

Elasticsearch 数据操作实例说明

1 度溢出处理

为了防止返回结果过于冗长,可以在查询中使用 size 参数控制每页数据量,默认值为 10。例如:

POST /_search?size=20

size 可选参数,默认大小为 10,从结果中获取数据。为了获取大量数据,可以通过 from 指标进行分页,默认值为 0

2 文档分词与查询

在 Elasticsearch 中,SNOW苦 відсут fined...

3 多条件查询实例

示例 1:多字段分词和条件查询

GET /db_test/person/_search?q=(age:500至800)&(intro:"研究")

示例 2:OR 和 AND 全文检索

GET /db_test/person/_search?q=(intro:"方鸿渐") OR (content:"方鸿渐")

示例 3:多字段多分词 AND 检索

GET /db_test/person/_search?query=(title:"朋友" AND content:"吃饭")

GET /db_test/person/_search?query=(title:"朋友" OR title:"吃饭") AND (content:"朋友" OR content:"吃饭")

示例 4:字段指定和多条件 OR

GET /db_test/person/_search?query=(intro:"研究") AND (content:"研究方鸿渐")

4 高亮显示

为了区分搜索结果中的关键词,可以在请求参数中设置 highlight。例如:

POST /db_test/person/_search{    "highlight": {        "pre_tags": ["%{highlight}"],        "post_tags": [""]     }}

这样,搜索结果中的指定字段会以特定格式强调。

5 停止词设置

/_mappings 索引中,可以设置词干脱水处理参数。这可以通过以下如下方式实现:

POST /_mappings{    "analysis": {        "analyzer": {            "standardTokenizerWithLowercase": {                "tokenizer": "standard",                "filter": ["lowercase"]            }        }    }}

这样,所有文本字段会自动降水。

6 单独字段查询

可以通过 _source 参数来限定返回的字段。例如:

GET /db_test/person/_search?_source=username,age

这样,每个文档响应中只包含 usernameage 两个字段,减少了不必要的数据传输量。

7 批量处理示例

可以通过批量操作 _bulk 统一处理大量数据。例如:

POST /_bulk{    "create": {        "_index": "db_news",        "_type": "news",        "_id": "1"    },    "title": "海军";    "content": "胜利的代价往往是巨大的"}

这样可以自动处理好 db_news 索引中 news 类型的多个文档。

上一篇:将jar包安装到本地仓库
下一篇:elasticsearch 不能root启动

发表评论

最新留言

关注你微信了!
[***.104.42.241]2025年05月08日 08时55分36秒