💎一站式轻松地调用各大LLM模型接口,支持GPT4、智谱、星火、月之暗面及文生图 广告
[TOC] [数据准备] ``` PUT /website/blog/1 { "title":"Search learn", "content":"This blog show us how to search Elasticsearch", "status":"published", "publish_date":"2019-01-01" } PUT /website/blog/2 { "title":"Search", "content":"We can learn more Elasticsearch here", "status":"published", "publish_date":"2014-01-01" } ``` ## **在多索引中搜索** - 同时在bank,teacher 两个索引中搜索 ``` GET bank,teacher/_search?q=age:100 ``` - 在所有索引中搜索 ``` GET _all/_search?q=age:100 ``` ## **查询所有文件** ``` GET website/_search { "query": { "match_all": {} } } ``` ## **`query` 查询条件与 `filter` 过滤条件** - 查询“title”中包含“Search”,“content”中包含“Elasticsearch”,“status”为“published”,“publish_date”>2015-01-01的文档 ``` GET _search { "query": { "bool": { "must": [ { "match": { "title": "Search" }}, { "match": { "content": "Elasticsearch" }} ], "filter": [ { "term": { "status": "published" }}, { "range": { "publish_date": { "gte": "2015-01-01" }}} ] } } } ``` ## **从多个字段中搜索 `multi_match`** - 从“title”,"content"中搜索“learn” ``` GET /website/_search { "query": { "multi_match": { "query": "learn", "fields": ["title","content"] } } } ``` - 从“title”,"content"中搜索“here” ``` GET /website/_search { "query": { "multi_match": { "query": "here", "fields": ["title","content"] } } } ``` ## **搜索统计 `_count `** ``` GET /website/blog/_count { "query":{ "term": {"title": "learn"} } } ```