使用match做全文检索,比较适合text类型,index=true
GET my_index/my_type/_search
{
"query": {
"match": {
"full_text": "xx yy"
}
}
}
term做词条查询,比较适合keyword类型,index=true
POST /_search -d
{
"from":10,
"size":5,
"query":{
"term":{
"eventname":"xx"
}
}
}
POST /_search -d
{
"from":10,
"size":5,
"query":{
"terms":{
"eventname":["xx","yy"]
}
}
}
{
"range" : {
"age" : {
"gte" : 1,
"lte" : 3,
"boost" : 2.0
}
}
}
gte:大于或等于(Greater-than or equal to)
gt:大于(Greater-than)
lte:小于或等于(Less-than or equal to)
lt:小于(Less-than)
ElasticSearch 5.0以后,string类型有重大变更,移除了string
类型,string
字段被拆分成两种新的数据类型: text
用于全文搜索的,而keyword
用于关键词搜索。
Text:会分词,然后进行索引
支持模糊、精确查询
不支持聚合
keyword:不进行分词,直接索引
支持模糊、精确查询
支持聚合
FR:徐海涛(hunk Xu)
QQ技术交流群:386476712