当前位置:网站首页>Es search summary
Es search summary
2022-07-24 09:12:00 【mynameisjinxiaokai】
Search for documents
There are two main ways to search ,URL Search and request body search , One is to write the search criteria in URL in , One is to write the request in the request body .
- URL Parameter condition search
grammar :GET /index/type/_search? Parameters
Argument parsing :
q: Use a field to query , for example q=book_name:book, It is based on book_name If there book To search .
sort: Use a field to sort , for example sort=cost:desc, It is based on cost Fields for descending order desc Sort .
other :fileds,timeout,analyzer【 These parameters are left in the request body search 】
Without parameters , by “ Full search ”
Multiple parameters use && Splicing
Example :
GET /douban/book/_search?q=book_summary:character
GET /douban/book/_search?q=book_author:Milan
GET /douban/book/_search?q=book_summary:a
GET /douban/book/_search?q=book_summary:a&&sort=book_pages:desc
GET /douban/book/_search?q=book_summary:a&&q=book_author:Milan
【 It is worth noting that , Please don't be right first text Sort data of type , This affects search , Just sort the integers 】
- Request body condition search
// Full search
GET /index/type/_search
GET /douban/book/_search
// Full search
GET /index/type/_search
{
"query": {
"match_all": {
}
}
}
GET /douban/book/_search
{
"query": {
"match_all": {
}
}
}
// Query the data of the specified field ( Full text search , If the search value has more than one word , The result of matching only one word can also be found ):
GET /index/type/_search
{
"query": {
"match": {
" Field name ": " Search value "
}
}
}
GET /douban/book/_search
{
"query": {
"match": {
"book_name": "A The"
}
}
}
// Search multiple fields using the same search value :
GET /index/type/_search
{
"query": {
"multi_match": {
"query": " Search value ",
"fields": [
" Search for fields 1"," Search for fields 2"]
}
}
}
GET /douban/book/_search
{
"query": {
"multi_match": {
"query": "A",
"fields": [
"book_name","book_summary"]
}
}
}
// Phrase query :【 Search value must match exactly , Does not split search values to search 】
GET /index/type/_search
{
"query": {
"match_phrase": {
" Field ": " Search value "
}
}
}
GET /douban/book/_search
{
"query": {
"match_phrase": {
"book_summary": "a character"
}
}
}
// Field filtering , The results of the query show only the specified fields
GET /product/book/_search
{
"query": {
" Query criteria "
},
"_source": [
" Fields to display 1",
" Fields to display 2"
]
}
GET /douban/book/_search
{
"query": {
"match": {
"book_name": "Story"
}
},
"_source": [
"book_name",
"book_id"
]
}
// Highlight query :【 Highlight according to the keywords of the query , The highlighted results will be displayed in the returned results and will be automatically displayed in the returned results highlight in , Keywords will be added <em> label 】
// If you want to highlight multiple fields , Multi field search is also required
GET /index/book/_search
{
"query": {
" Query criteria "
},
"highlight": {
"fields": {
" Highlighted field name 1": {
}
}
}
}
GET /douban/book/_search
{
"query": {
"match": {
"book_summary": "Story"
}
},
"highlight": {
"fields": {
"book_summary":{
}
}
}
}
GET /douban/book/_search
{
"query": {
"multi_match": {
"query": "Story",
"fields": [
"book_name","book_summary"]
}
},
"highlight": {
"fields": {
"book_summary":{
},
"book_name":{
}
}
}
}
The above shows about full search 、 Single field value full text search 、 Multi field single search value full text search 、 Phrase search 、 Field filtering 、 Highlight the search code .
Because using different search values for multiple fields involves condition splicing , So let's talk about it alone .
Pre knowledge explanation : For conditional splicing , stay SQL There is and,or,not, stay ElasticSearch Not quite the same. , Let's explain one by one :
bool: It is used to indicate that the statement in it is a combination of multiple conditions , Used to wrap multiple conditions .
should: There can be multiple conditions , The query result must meet one or more of the query criteria .
must: Many of the conditions must be true
must_not: Many conditions in it must not be tenable
Example :
// The title of the book must contain Story Of
GET /douban/book/_search
{
"query": {
"bool": {
"must": [
{
"match":{
"book_name":"Story"
}
}
]
}
}
}
// The title must not contain Story Of
GET /douban/book/_search
{
"query": {
"bool": {
"must_not": [
{
"match":{
"book_name":"Story"
}
}
]
}
}
}
// The title must not contain Story, The title of the book contains Adventures or Immortality Of
GET /douban/book/_search
{
"query": {
"bool": {
"must_not": [
{
"match":{
"book_name":"Story"
}
}
],
"should": [
{
"match": {
"book_name": "Adventures"
}
},
{
"match": {
"book_name": "Immortality"
}
}
]
}
}
}
// stay should、must、must_not Many conditions can be put in these
GET /douban/book/_search
{
"query": {
"bool": {
"must_not": [
{
"match":{
"book_name":"Story"
}
},
{
"match": {
"book_name": "Adventures"
}
}
]
}
}
}
// If it's a single condition , You can also write , Omit []:
GET /douban/book/_search
{
"query": {
"bool": {
"must_not": {
"match":{
"book_name":"Story"
}
}
}
}
}
// You can also nest conditions , That is to say, another layer of nesting bool, But pay attention to logic , for example :
// Query out ( The title of the book has story) perhaps ( The title of the book has The And the author's name is David) Of , The second is whether it can be established or not .
GET /douban/book/_search
{
"query": {
"bool": {
"should": [
{
"match": {
"book_name": "Story"
}
},
{
"bool": {
"must": [
{
"match": {
"book_name": "The"
}
},
{
"match": {
"book_author": "David"
}
}
]
}
}
]
}
}
}
Summary :
It says URL Parameter condition search and request body condition search , About full search 、 Single field value full text search 、 Multi field single search value full text search 、 Phrase search 、 Field filtering 、 How to use highlight search , It's based on bool、should、must、must_not Multi criteria search for , The above knowledge has been able to achieve some basic search functions . But there is still some knowledge because it is more obscure , So I'll leave it to the next chapter , For example, assign a word breaker to a search 、 Specify the number of matches for multiple conditions 、 Scrolling queries and so on .
It says URL Parameter condition search and request body condition search .URL The parameter conditions are written in URL Inside , use ? To attach parameters ,q Used to specify search fields . The request body parameter writes the condition in the request body ,query It's the outermost package ,match_all Used to query all ,match Used to search a field using a specified search value ,match_phrase Used to search for successive searches ,_source Used to filter fields ( And query At the same level ,[] Inside is the field name ),highlight Used to highlight search ( And query At the same level , Inside is {field:{ Field name 1:{}, Field name 2:{}}}),bool、should、must、must_not Used for multi criteria search .
边栏推荐
- Tiktok's "online celebrity" was poached by Amazon and broadcast on Amazon live platform
- Android系统安全 — 5.2-APK V1签名介绍
- How to open the port number of the server, and the corresponding port of common network services
- Unity solves the package manager "you see to be offline"
- 2021 robocom world robot developer competition - undergraduate group (Preliminary) problem solution
- Tiktok live broadcast with goods marketing play
- Advantages of using partitions
- Code random notes_ Linked list_ Turn over the linked list in groups of 25K
- Publish your own library on NPM
- Tiktok shop platform will take disciplinary measures against sellers who violate rules and policies
猜你喜欢

Houdini 笔记

One year after I came to Ali, I ushered in my first job change

dp最长公共子序列详细版本(LCS)

Data center: started in Alibaba and started in Daas

Little dolphin "transformed" into a new intelligent scheduling engine, which can be explained in simple terms in the practical development and application of DDS

Xtrabackup realizes full backup and incremental backup of MySQL

C语言练习题目+答案:

Re6:读论文 LeSICiN: A Heterogeneous Graph-based Approach for Automatic Legal Statute Identification fro

Opencv Chinese document 4.0.0 learning notes (updating...)

数据中台:始于阿里,兴于DaaS
随机推荐
One year after I came to Ali, I ushered in my first job change
Sword finger offer II 024. reverse linked list
& 和 &&、| 和 || 的区别
Functions of tiktok enterprise number
The difference between classification and regression
Seven data show the impact of tiktok's combination of payment and organic content
CodeBlocks shortcut key operation Xiaoquan
我们说的组件自定义事件到底是什么?
TiFlash 源码阅读(五) DeltaTree 存储引擎设计及实现分析 - Part 2
Aruba learning notes 06 wireless control AC basic configuration (CLI)
Android system security - 5.2-apk V1 signature introduction
Account 1-2
【汇编语言实战】(二)、编写一程序计算表达式w=v-(x+y+z-51)的值(含代码、过程截图)
The detailed process of building discuz forum is easy to understand
Attack and defense world ----- confusion1
2021 robocom world robot developer competition - undergraduate group (Preliminary) problem solution
The next stop of data visualization platform | gifts from domestic open source data visualization datart "super iron powder"
gnuplot软件学习笔记
JUC强大的辅助类
[example of URDF exercise based on ROS] use of four wheeled robot and camera