Elasticsearch 使用记录

背景

Elasticsearch 是一个分布式的搜索和分析引擎

Elasticsearch is a highly scalable open-source full-text search and analytics engine. It allows you to store, search, and analyze big volumes of data quickly and in near real time. It is generally used as the underlying engine/technology that powers applications that have complex search features and requirements.

安装

支持直接安装也可以docker安装 , 更多阅读 安装Elasticsearch 安装Kibana

基础

skills

  • Search for exact values
  • Full-text search
  • Vector search

query

  • match / match_phrase / multi_match(^boost | type phrase)
    • match查询执行的是分词搜索,它会将搜索的文本进行分词,然后对分词后的项进行匹配
    • match_phrase查询执行的是短语搜索,它会确保搜索的短语在文档中以指定的顺序连续出现
    • The multi_match query builds on the match query to allow multi-field queries
  • range / term
  • bool(must | must_not | should | filter)

代码案例

GET books/_search
{  
"query":  { 
	"match": {
		 "author": "Joshua"    
			 }  
		}
}

GET books/_search
{  
"query": {    
	"match": {     
		 "author": {         
			 "query": "Joshua Schildt",         
			 "operator": "AND"     
			  }    
		  }  
	  }
  }

GET books/_search
{  
"query": {    
	"multi_match": {       
		"query": "Java",       
		"fields": ["title","synopsis"]     
		}  
	}
}

GET books/_search
{  
	"query": {    
		"multi_match": {       
			"query": "Java",      
			"fields": ["title^3","synopsis"]    
			}  
		}
}

GET books/_search
{  
	"query": {    
		"match_phrase": {        
			"synopsis": "must-have book for every Java programmer"      
			}  
		}
}

GET books/_search
{  
	"query": {    
		"match": {      
			"tags": {        
				"query": "Komputer",        
				"fuzziness": 1       
				}    
			}  
		}
}

GET books/_search
{
	"_source": ["title","edition"],   
	"query": {    
		"term": {      
			 "edition": {        
			  "value": 3     
			   }   
			} 
		 }
 }

GET books/_search
{
	"query": {    
		"range": {       
			"amazon_rating": {        
				"gte": 4.5,         
				"lte": 5      
					 }   
				  }  
		  }
  }

参考