一、基本概念
1、index(索引)
动词,相当于MySQL中的insert
名词,相当于MySQL中的Database
2、Type(类型)
在index(索引)中,可以定义一个或多个类型
类似于MySQL中的Table:每一种类型的数据放在一起
3、Document(文档)
保存在某个索引(Index)下,某中类型(Type)的一个数据(Document),文档是JSON格式的,Document就像是MySQL中的某个Table里面的内容
二、put&post新增数据
PUT http://119.29.0.100:9200/customer/external/1
//元数据
{
"_index": "customer", //在哪个索引下
"_type": "external", //在哪个类型下
"_id": "1", //数据id
"_version": 1, //数据的版本
"result": "created", //最终结果
"_shards": { //分片的信息
"total": 2,
"successful": 1,
"failed": 0
},
"_seq_no": 0,
"_primary_term": 1
}
GET http://119.29.0.100:9200/customer/external/1
{
"_index": "customer", //数据在哪条索引下
"_type": "external", //数据是哪个类型
"_id": "1", //数据的id
"_version": 2, //版本号
"_seq_no": 1, //并发控制字段,每次更新就会+1,用来做乐观锁
"_primary_term": 1, //同上,主分片重新分配,如重启,就会变化,乐观锁操作
"found": true, //是否找到这个数据
"_source": { //真实数据
"name": "John Doe"
}
}
三、kibana实例
POST /customer/external/_bulk
{"index": {"_id": "1"}}
{"name": "John Doe"}
{"index": {"_id": "2"}}
{"name": "Jane Doe"}
#! Deprecation: [types removal] Specifying types in bulk requests is deprecated.
{
"took" : 276, //我们花费了多少毫秒
"errors" : false, //没有发生错误
"items" : [ //每一条记录,每一条记录独立操作,不会有一条记录出问题其他就全错
{
"index" : {
"_index" : "customer",
"_type" : "external",
"_id" : "1",
"_version" : 1,
"result" : "created",
"_shards" : {
"total" : 2,
"successful" : 1,
"failed" : 0
},
"_seq_no" : 0,
"_primary_term" : 1,
"status" : 201
}
},
{
"index" : {
"_index" : "customer",
"_type" : "external",
"_id" : "2",
"_version" : 1,
"result" : "created",
"_shards" : {
"total" : 2,
"successful" : 1,
"failed" : 0
},
"_seq_no" : 1,
"_primary_term" : 1,
"status" : 201
}
}
]
}
POST /_bulk
{"delete": {"_index": "website", "_type": "blog", "_id": "123"}}
{"create": {"_index": "website", "_type": "blog", "_id": "123"}}
{"title": "My first blog post"}
{"index": {"_index": "website", "_type": "blog"}}
{"title": "My second blog post"}
{"update": {"_index": "website", "_type": "blog", "_id": "123"}}
{"doc": {"title": "My updated blog post"}}
#! Deprecation: [types removal] Specifying types in bulk requests is deprecated.
{
"took" : 345,
"errors" : false,
"items" : [
{
"delete" : {
"_index" : "website",
"_type" : "blog",
"_id" : "123",
"_version" : 1,
"result" : "not_found",
"_shards" : {
"total" : 2,
"successful" : 1,
"failed" : 0
},
"_seq_no" : 0,
"_primary_term" : 1,
"status" : 404
}
},
{
"create" : {
"_index" : "website",
"_type" : "blog",
"_id" : "123",
"_version" : 2,
"result" : "created",
"_shards" : {
"total" : 2,
"successful" : 1,
"failed" : 0
},
"_seq_no" : 1,
"_primary_term" : 1,
"status" : 201
}
},
{
"index" : {
"_index" : "website",
"_type" : "blog",
"_id" : "xY5K6H8Bu-L-iarzG9eT",
"_version" : 1,
"result" : "created",
"_shards" : {
"total" : 2,
"successful" : 1,
"failed" : 0
},
"_seq_no" : 2,
"_primary_term" : 1,
"status" : 201
}
},
{
"update" : {
"_index" : "website",
"_type" : "blog",
"_id" : "123",
"_version" : 3,
"result" : "updated",
"_shards" : {
"total" : 2,
"successful" : 1,
"failed" : 0
},
"_seq_no" : 3,
"_primary_term" : 1,
"status" : 200
}
}
]
}
四、进阶检索
1、SearchAPI
ES支持两种基本方式检索:
- 一个是通过使用 REST request URI 发送搜索参数(uri+检索参数)
- 另一个是通过使用 REST request body 来发送它们(uri+请求体)
GET bank/_search?q=*&sort=account_number:asc
//q=* 查全部信息
//sort=account_number:asc 对账号进行升序排列
//默认分页查询
{
"took" : 57, //话费了57毫秒
"timed_out" : false, //是否超时
"_shards" : { //集群的内容
"total" : 1,
"successful" : 1,
"skipped" : 0,
"failed" : 0
},
"hits" : { //命中的记录
"total" : {
"value" : 1000, //有多少条记录被匹配到
"relation" : "eq"
},
"max_score" : null, //最大得分
"hits" : [ //所有命中的记录
{
"_index" : "bank", //索引
"_type" : "account", //类型
"_id" : "0", //记录的唯一id
"_score" : null, //当前记录的得分
"_source" : { //保存的数据内容
"account_number" : 0,
"balance" : 16623,
"firstname" : "Bradshaw",
"lastname" : "Mckenzie",
"age" : 29,
"gender" : "F",
"address" : "244 Columbus Place",
"employer" : "Euron",
"email" : "bradshawmckenzie@euron.com",
"city" : "Hobucken",
"state" : "CO"
},
"sort" : [ //在搜索出来的数据中的排序
0
]
},
{
"_index" : "bank",
"_type" : "account",
"_id" : "1",
"_score" : null,
"_source" : {
"account_number" : 1,
"balance" : 39225,
"firstname" : "Amber",
"lastname" : "Duke",
"age" : 32,
"gender" : "M",
"address" : "880 Holmes Lane",
"employer" : "Pyrami",
"email" : "amberduke@pyrami.com",
"city" : "Brogan",
"state" : "IL"
},
"sort" : [
1
]
},
{
"_index" : "bank",
"_type" : "account",
"_id" : "2",
"_score" : null,
"_source" : {
"account_number" : 2,
"balance" : 28838,
"firstname" : "Roberta",
"lastname" : "Bender",
"age" : 22,
"gender" : "F",
"address" : "560 Kingsway Place",
"employer" : "Chillium",
"email" : "robertabender@chillium.com",
"city" : "Bennett",
"state" : "LA"
},
"sort" : [
2
]
},
{
"_index" : "bank",
"_type" : "account",
"_id" : "3",
"_score" : null,
"_source" : {
"account_number" : 3,
"balance" : 44947,
"firstname" : "Levine",
"lastname" : "Burks",
"age" : 26,
"gender" : "F",
"address" : "328 Wilson Avenue",
"employer" : "Amtap",
"email" : "levineburks@amtap.com",
"city" : "Cochranville",
"state" : "HI"
},
"sort" : [
3
]
},
{
"_index" : "bank",
"_type" : "account",
"_id" : "4",
"_score" : null,
"_source" : {
"account_number" : 4,
"balance" : 27658,
"firstname" : "Rodriquez",
"lastname" : "Flores",
"age" : 31,
"gender" : "F",
"address" : "986 Wyckoff Avenue",
"employer" : "Tourmania",
"email" : "rodriquezflores@tourmania.com",
"city" : "Eastvale",
"state" : "HI"
},
"sort" : [
4
]
},
{
"_index" : "bank",
"_type" : "account",
"_id" : "5",
"_score" : null,
"_source" : {
"account_number" : 5,
"balance" : 29342,
"firstname" : "Leola",
"lastname" : "Stewart",
"age" : 30,
"gender" : "F",
"address" : "311 Elm Place",
"employer" : "Diginetic",
"email" : "leolastewart@diginetic.com",
"city" : "Fairview",
"state" : "NJ"
},
"sort" : [
5
]
},
{
"_index" : "bank",
"_type" : "account",
"_id" : "6",
"_score" : null,
"_source" : {
"account_number" : 6,
"balance" : 5686,
"firstname" : "Hattie",
"lastname" : "Bond",
"age" : 36,
"gender" : "M",
"address" : "671 Bristol Street",
"employer" : "Netagy",
"email" : "hattiebond@netagy.com",
"city" : "Dante",
"state" : "TN"
},
"sort" : [
6
]
},
{
"_index" : "bank",
"_type" : "account",
"_id" : "7",
"_score" : null,
"_source" : {
"account_number" : 7,
"balance" : 39121,
"firstname" : "Levy",
"lastname" : "Richard",
"age" : 22,
"gender" : "M",
"address" : "820 Logan Street",
"employer" : "Teraprene",
"email" : "levyrichard@teraprene.com",
"city" : "Shrewsbury",
"state" : "MO"
},
"sort" : [
7
]
},
{
"_index" : "bank",
"_type" : "account",
"_id" : "8",
"_score" : null,
"_source" : {
"account_number" : 8,
"balance" : 48868,
"firstname" : "Jan",
"lastname" : "Burns",
"age" : 35,
"gender" : "M",
"address" : "699 Visitation Place",
"employer" : "Glasstep",
"email" : "janburns@glasstep.com",
"city" : "Wakulla",
"state" : "AZ"
},
"sort" : [
8
]
},
{
"_index" : "bank",
"_type" : "account",
"_id" : "9",
"_score" : null,
"_source" : {
"account_number" : 9,
"balance" : 24776,
"firstname" : "Opal",
"lastname" : "Meadows",
"age" : 39,
"gender" : "M",
"address" : "963 Neptune Avenue",
"employer" : "Cedward",
"email" : "opalmeadows@cedward.com",
"city" : "Olney",
"state" : "OH"
},
"sort" : [
9
]
}
]
}
}
GET bank/_search
{
"query": {
"match_all": {} //匹配所有:详细规则
},
"sort": [ //排序规则
{
"account_number": "asc" //按照账号升序排列
},
{
"balance": "desc"
}
]
}
{
"took" : 2,
"timed_out" : false,
"_shards" : {
"total" : 1,
"successful" : 1,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : {
"value" : 1000,
"relation" : "eq"
},
"max_score" : null,
"hits" : [
{
"_index" : "bank",
"_type" : "account",
"_id" : "0",
"_score" : null,
"_source" : {
"account_number" : 0,
"balance" : 16623,
"firstname" : "Bradshaw",
"lastname" : "Mckenzie",
"age" : 29,
"gender" : "F",
"address" : "244 Columbus Place",
"employer" : "Euron",
"email" : "bradshawmckenzie@euron.com",
"city" : "Hobucken",
"state" : "CO"
},
"sort" : [
0,
16623
]
},
{
"_index" : "bank",
"_type" : "account",
"_id" : "1",
"_score" : null,
"_source" : {
"account_number" : 1,
"balance" : 39225,
"firstname" : "Amber",
"lastname" : "Duke",
"age" : 32,
"gender" : "M",
"address" : "880 Holmes Lane",
"employer" : "Pyrami",
"email" : "amberduke@pyrami.com",
"city" : "Brogan",
"state" : "IL"
},
"sort" : [
1,
39225
]
},
{
"_index" : "bank",
"_type" : "account",
"_id" : "2",
"_score" : null,
"_source" : {
"account_number" : 2,
"balance" : 28838,
"firstname" : "Roberta",
"lastname" : "Bender",
"age" : 22,
"gender" : "F",
"address" : "560 Kingsway Place",
"employer" : "Chillium",
"email" : "robertabender@chillium.com",
"city" : "Bennett",
"state" : "LA"
},
"sort" : [
2,
28838
]
},
{
"_index" : "bank",
"_type" : "account",
"_id" : "3",
"_score" : null,
"_source" : {
"account_number" : 3,
"balance" : 44947,
"firstname" : "Levine",
"lastname" : "Burks",
"age" : 26,
"gender" : "F",
"address" : "328 Wilson Avenue",
"employer" : "Amtap",
"email" : "levineburks@amtap.com",
"city" : "Cochranville",
"state" : "HI"
},
"sort" : [
3,
44947
]
},
{
"_index" : "bank",
"_type" : "account",
"_id" : "4",
"_score" : null,
"_source" : {
"account_number" : 4,
"balance" : 27658,
"firstname" : "Rodriquez",
"lastname" : "Flores",
"age" : 31,
"gender" : "F",
"address" : "986 Wyckoff Avenue",
"employer" : "Tourmania",
"email" : "rodriquezflores@tourmania.com",
"city" : "Eastvale",
"state" : "HI"
},
"sort" : [
4,
27658
]
},
{
"_index" : "bank",
"_type" : "account",
"_id" : "5",
"_score" : null,
"_source" : {
"account_number" : 5,
"balance" : 29342,
"firstname" : "Leola",
"lastname" : "Stewart",
"age" : 30,
"gender" : "F",
"address" : "311 Elm Place",
"employer" : "Diginetic",
"email" : "leolastewart@diginetic.com",
"city" : "Fairview",
"state" : "NJ"
},
"sort" : [
5,
29342
]
},
{
"_index" : "bank",
"_type" : "account",
"_id" : "6",
"_score" : null,
"_source" : {
"account_number" : 6,
"balance" : 5686,
"firstname" : "Hattie",
"lastname" : "Bond",
"age" : 36,
"gender" : "M",
"address" : "671 Bristol Street",
"employer" : "Netagy",
"email" : "hattiebond@netagy.com",
"city" : "Dante",
"state" : "TN"
},
"sort" : [
6,
5686
]
},
{
"_index" : "bank",
"_type" : "account",
"_id" : "7",
"_score" : null,
"_source" : {
"account_number" : 7,
"balance" : 39121,
"firstname" : "Levy",
"lastname" : "Richard",
"age" : 22,
"gender" : "M",
"address" : "820 Logan Street",
"employer" : "Teraprene",
"email" : "levyrichard@teraprene.com",
"city" : "Shrewsbury",
"state" : "MO"
},
"sort" : [
7,
39121
]
},
{
"_index" : "bank",
"_type" : "account",
"_id" : "8",
"_score" : null,
"_source" : {
"account_number" : 8,
"balance" : 48868,
"firstname" : "Jan",
"lastname" : "Burns",
"age" : 35,
"gender" : "M",
"address" : "699 Visitation Place",
"employer" : "Glasstep",
"email" : "janburns@glasstep.com",
"city" : "Wakulla",
"state" : "AZ"
},
"sort" : [
8,
48868
]
},
{
"_index" : "bank",
"_type" : "account",
"_id" : "9",
"_score" : null,
"_source" : {
"account_number" : 9,
"balance" : 24776,
"firstname" : "Opal",
"lastname" : "Meadows",
"age" : 39,
"gender" : "M",
"address" : "963 Neptune Avenue",
"employer" : "Cedward",
"email" : "opalmeadows@cedward.com",
"city" : "Olney",
"state" : "OH"
},
"sort" : [
9,
24776
]
}
]
}
}
2、Query DSL
1)、基本语法格式
Elasticsearch提供了一个可以执行查询的JSON风格的DSL(domain-specific language领域特定语言)。这个被称为Query DSL。改查询语言非常全面,并且刚开始的时候感觉有点复杂,真正学好它的方法是从一些基础的实例开始的。
五、match_all
GET bank/_search
{
"query": {
"match_all": {}
}
}
GET bank/_search
{
"query": {
"match_all": {}
},
"sort": [
{
"balance": {
"order": "desc"
}
}
]
}
GET bank/_search
{
"query": {
"match_all": {}
},
"sort": [
{
"balance": "desc"
}
]
}
GET bank/_search
{
"query": {
"match_all": {}
},
"sort": [
{
"balance": "desc"
}
],
"from": 0,
"size": 2,
"_source": ["balance", "firstname"]
}
六、match全文检索
GET bank/_search
{
"query": {
"match": {
"account_number": "20"
}
}
}
GET bank/_search
{
"query": {
"match": {
"address": "Kings"
}
}
}
{
"took" : 26,
"timed_out" : false,
"_shards" : {
"total" : 1,
"successful" : 1,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : {
"value" : 2,
"relation" : "eq"
},
"max_score" : 5.9908285, //最大得分
"hits" : [
{
"_index" : "bank",
"_type" : "account",
"_id" : "20",
"_score" : 5.9908285, //得分
"_source" : {
"account_number" : 20,
"balance" : 16418,
"firstname" : "Elinor",
"lastname" : "Ratliff",
"age" : 36,
"gender" : "M",
"address" : "282 Kings Place",
"employer" : "Scentric",
"email" : "elinorratliff@scentric.com",
"city" : "Ribera",
"state" : "WA"
}
},
{
"_index" : "bank",
"_type" : "account",
"_id" : "722",
"_score" : 5.9908285,
"_source" : {
"account_number" : 722,
"balance" : 27256,
"firstname" : "Roberts",
"lastname" : "Beasley",
"age" : 34,
"gender" : "F",
"address" : "305 Kings Hwy",
"employer" : "Quintity",
"email" : "robertsbeasley@quintity.com",
"city" : "Hayden",
"state" : "PA"
}
}
]
}
}
GET bank/_search
{
"query": {
"match": {
"address": "mill lane"
}
}
}
##全文检索按照评分进行排序,会对检索条件进行分词匹配
//包含mill或lane都会被检索出
{
"took" : 2,
"timed_out" : false,
"_shards" : {
"total" : 1,
"successful" : 1,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : {
"value" : 19,
"relation" : "eq"
},
"max_score" : 9.507477,
"hits" : [
{
"_index" : "bank",
"_type" : "account",
"_id" : "136",
"_score" : 9.507477,
"_source" : {
"account_number" : 136,
"balance" : 45801,
"firstname" : "Winnie",
"lastname" : "Holland",
"age" : 38,
"gender" : "M",
"address" : "198 Mill Lane",
"employer" : "Neteria",
"email" : "winnieholland@neteria.com",
"city" : "Urie",
"state" : "IL"
}
},
{
"_index" : "bank",
"_type" : "account",
"_id" : "970",
"_score" : 5.4032025,
"_source" : {
"account_number" : 970,
"balance" : 19648,
"firstname" : "Forbes",
"lastname" : "Wallace",
"age" : 28,
"gender" : "M",
"address" : "990 Mill Road",
"employer" : "Pheast",
"email" : "forbeswallace@pheast.com",
"city" : "Lopezo",
"state" : "AK"
}
},
{
"_index" : "bank",
"_type" : "account",
"_id" : "345",
"_score" : 5.4032025,
"_source" : {
"account_number" : 345,
"balance" : 9812,
"firstname" : "Parker",
"lastname" : "Hines",
"age" : 38,
"gender" : "M",
"address" : "715 Mill Avenue",
"employer" : "Baluba",
"email" : "parkerhines@baluba.com",
"city" : "Blackgum",
"state" : "KY"
}
},
{
"_index" : "bank",
"_type" : "account",
"_id" : "472",
"_score" : 5.4032025,
"_source" : {
"account_number" : 472,
"balance" : 25571,
"firstname" : "Lee",
"lastname" : "Long",
"age" : 32,
"gender" : "F",
"address" : "288 Mill Street",
"employer" : "Comverges",
"email" : "leelong@comverges.com",
"city" : "Movico",
"state" : "MT"
}
},
{
"_index" : "bank",
"_type" : "account",
"_id" : "1",
"_score" : 4.1042743,
"_source" : {
"account_number" : 1,
"balance" : 39225,
"firstname" : "Amber",
"lastname" : "Duke",
"age" : 32,
"gender" : "M",
"address" : "880 Holmes Lane",
"employer" : "Pyrami",
"email" : "amberduke@pyrami.com",
"city" : "Brogan",
"state" : "IL"
}
},
{
"_index" : "bank",
"_type" : "account",
"_id" : "70",
"_score" : 4.1042743,
"_source" : {
"account_number" : 70,
"balance" : 38172,
"firstname" : "Deidre",
"lastname" : "Thompson",
"age" : 33,
"gender" : "F",
"address" : "685 School Lane",
"employer" : "Netplode",
"email" : "deidrethompson@netplode.com",
"city" : "Chestnut",
"state" : "GA"
}
},
{
"_index" : "bank",
"_type" : "account",
"_id" : "556",
"_score" : 4.1042743,
"_source" : {
"account_number" : 556,
"balance" : 36420,
"firstname" : "Collier",
"lastname" : "Odonnell",
"age" : 35,
"gender" : "M",
"address" : "591 Nolans Lane",
"employer" : "Sultraxin",
"email" : "collierodonnell@sultraxin.com",
"city" : "Fulford",
"state" : "MD"
}
},
{
"_index" : "bank",
"_type" : "account",
"_id" : "568",
"_score" : 4.1042743,
"_source" : {
"account_number" : 568,
"balance" : 36628,
"firstname" : "Lesa",
"lastname" : "Maynard",
"age" : 29,
"gender" : "F",
"address" : "295 Whitty Lane",
"employer" : "Coash",
"email" : "lesamaynard@coash.com",
"city" : "Broadlands",
"state" : "VT"
}
},
{
"_index" : "bank",
"_type" : "account",
"_id" : "715",
"_score" : 4.1042743,
"_source" : {
"account_number" : 715,
"balance" : 23734,
"firstname" : "Tammi",
"lastname" : "Hodge",
"age" : 24,
"gender" : "M",
"address" : "865 Church Lane",
"employer" : "Netur",
"email" : "tammihodge@netur.com",
"city" : "Lacomb",
"state" : "KS"
}
},
{
"_index" : "bank",
"_type" : "account",
"_id" : "449",
"_score" : 4.1042743,
"_source" : {
"account_number" : 449,
"balance" : 41950,
"firstname" : "Barnett",
"lastname" : "Cantrell",
"age" : 39,
"gender" : "F",
"address" : "945 Bedell Lane",
"employer" : "Zentility",
"email" : "barnettcantrell@zentility.com",
"city" : "Swartzville",
"state" : "ND"
}
}
]
}
}
七、match_phrase短语匹配
GET bank/_search
{
"query": {
"match_phrase": {
"address": "mill lane"
}
}
}
八、multi_match多字段匹配
GET bank/_search
{
"query": {
"multi_match": {
"query": "mill movico",
"fields": [
"address",
"city"
]
}
}
}
九、bool复合查询
GET bank/_search
{
"query": {
"bool": {
"must": [
{
"match": {
"gender": "M"
}
},
{
"match": {
"address": "mill"
}
}
],
"must_not": [
{
"match": {
"age": "28"
}
}
],
"should": [
{
"match": {
"lastname": "Wallace"
}
}
]
}
}
}
十、filter过滤
并不是所有的查询都需要产生分数,特别是那些仅用于“filtering”(过滤)的文档。为了不计算分数Elasticsearch会自动检查场景并且优化查询的执行
GET bank/_search
{
"query": {
"bool": {
"must": [
{
"range": {
"age": {
"gte": 18,
"lte": 30
}
}
}
],
"must_not": [
{
"match": {
"age": "18"
}
}
],
"should": [
{
"match": {
"lastname": "Wallace"
}
}
],
"filter": {
"range": {
"age": {
"gte": 18,
"lte": 30
}
}
}
}
}
}
GET bank/_search
{
"query": {
"bool": {
"filter": {
"range": {
"age": {
"gte": 18,
"lte": 30
}
}
}
}
}
}
十一、term查询
GET bank/_search
{
"query": {
"match": {
"age": "28"
}
}
}
{
"took" : 0,
"timed_out" : false,
"_shards" : {
"total" : 1,
"successful" : 1,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : {
"value" : 51,
"relation" : "eq"
},
"max_score" : 1.0,
"hits" : [
{
"_index" : "bank",
"_type" : "account",
"_id" : "13",
"_score" : 1.0,
"_source" : {
"account_number" : 13,
"balance" : 32838,
"firstname" : "Nanette",
"lastname" : "Bates",
"age" : 28,
"gender" : "F",
"address" : "789 Madison Street",
"employer" : "Quility",
"email" : "nanettebates@quility.com",
"city" : "Nogal",
"state" : "VA"
}
},
{
"_index" : "bank",
"_type" : "account",
"_id" : "107",
"_score" : 1.0,
"_source" : {
"account_number" : 107,
"balance" : 48844,
"firstname" : "Randi",
"lastname" : "Rich",
"age" : 28,
"gender" : "M",
"address" : "694 Jefferson Street",
"employer" : "Netplax",
"email" : "randirich@netplax.com",
"city" : "Bellfountain",
"state" : "SC"
}
},
{
"_index" : "bank",
"_type" : "account",
"_id" : "119",
"_score" : 1.0,
"_source" : {
"account_number" : 119,
"balance" : 49222,
"firstname" : "Laverne",
"lastname" : "Johnson",
"age" : 28,
"gender" : "F",
"address" : "302 Howard Place",
"employer" : "Senmei",
"email" : "lavernejohnson@senmei.com",
"city" : "Herlong",
"state" : "DC"
}
},
{
"_index" : "bank",
"_type" : "account",
"_id" : "176",
"_score" : 1.0,
"_source" : {
"account_number" : 176,
"balance" : 18607,
"firstname" : "Kemp",
"lastname" : "Walters",
"age" : 28,
"gender" : "F",
"address" : "906 Howard Avenue",
"employer" : "Eyewax",
"email" : "kempwalters@eyewax.com",
"city" : "Why",
"state" : "KY"
}
},
{
"_index" : "bank",
"_type" : "account",
"_id" : "359",
"_score" : 1.0,
"_source" : {
"account_number" : 359,
"balance" : 29927,
"firstname" : "Vanessa",
"lastname" : "Harvey",
"age" : 28,
"gender" : "F",
"address" : "679 Rutledge Street",
"employer" : "Zentime",
"email" : "vanessaharvey@zentime.com",
"city" : "Williston",
"state" : "IL"
}
},
{
"_index" : "bank",
"_type" : "account",
"_id" : "506",
"_score" : 1.0,
"_source" : {
"account_number" : 506,
"balance" : 43440,
"firstname" : "Davidson",
"lastname" : "Salas",
"age" : 28,
"gender" : "M",
"address" : "731 Cleveland Street",
"employer" : "Sequitur",
"email" : "davidsonsalas@sequitur.com",
"city" : "Lloyd",
"state" : "ME"
}
},
{
"_index" : "bank",
"_type" : "account",
"_id" : "669",
"_score" : 1.0,
"_source" : {
"account_number" : 669,
"balance" : 16934,
"firstname" : "Jewel",
"lastname" : "Estrada",
"age" : 28,
"gender" : "M",
"address" : "896 Meeker Avenue",
"employer" : "Zilla",
"email" : "jewelestrada@zilla.com",
"city" : "Goodville",
"state" : "PA"
}
},
{
"_index" : "bank",
"_type" : "account",
"_id" : "708",
"_score" : 1.0,
"_source" : {
"account_number" : 708,
"balance" : 34002,
"firstname" : "May",
"lastname" : "Ortiz",
"age" : 28,
"gender" : "F",
"address" : "244 Chauncey Street",
"employer" : "Syntac",
"email" : "mayortiz@syntac.com",
"city" : "Munjor",
"state" : "ID"
}
},
{
"_index" : "bank",
"_type" : "account",
"_id" : "746",
"_score" : 1.0,
"_source" : {
"account_number" : 746,
"balance" : 15970,
"firstname" : "Marguerite",
"lastname" : "Wall",
"age" : 28,
"gender" : "F",
"address" : "364 Crosby Avenue",
"employer" : "Aquoavo",
"email" : "margueritewall@aquoavo.com",
"city" : "Jeff",
"state" : "MI"
}
},
{
"_index" : "bank",
"_type" : "account",
"_id" : "758",
"_score" : 1.0,
"_source" : {
"account_number" : 758,
"balance" : 15739,
"firstname" : "Berta",
"lastname" : "Short",
"age" : 28,
"gender" : "M",
"address" : "149 Surf Avenue",
"employer" : "Ozean",
"email" : "bertashort@ozean.com",
"city" : "Odessa",
"state" : "UT"
}
}
]
}
}
GET bank/_search
{
"query": {
"term": {
"age": "28"
}
}
}
{
"took" : 1,
"timed_out" : false,
"_shards" : {
"total" : 1,
"successful" : 1,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : {
"value" : 51,
"relation" : "eq"
},
"max_score" : 1.0,
"hits" : [
{
"_index" : "bank",
"_type" : "account",
"_id" : "13",
"_score" : 1.0,
"_source" : {
"account_number" : 13,
"balance" : 32838,
"firstname" : "Nanette",
"lastname" : "Bates",
"age" : 28,
"gender" : "F",
"address" : "789 Madison Street",
"employer" : "Quility",
"email" : "nanettebates@quility.com",
"city" : "Nogal",
"state" : "VA"
}
},
{
"_index" : "bank",
"_type" : "account",
"_id" : "107",
"_score" : 1.0,
"_source" : {
"account_number" : 107,
"balance" : 48844,
"firstname" : "Randi",
"lastname" : "Rich",
"age" : 28,
"gender" : "M",
"address" : "694 Jefferson Street",
"employer" : "Netplax",
"email" : "randirich@netplax.com",
"city" : "Bellfountain",
"state" : "SC"
}
},
{
"_index" : "bank",
"_type" : "account",
"_id" : "119",
"_score" : 1.0,
"_source" : {
"account_number" : 119,
"balance" : 49222,
"firstname" : "Laverne",
"lastname" : "Johnson",
"age" : 28,
"gender" : "F",
"address" : "302 Howard Place",
"employer" : "Senmei",
"email" : "lavernejohnson@senmei.com",
"city" : "Herlong",
"state" : "DC"
}
},
{
"_index" : "bank",
"_type" : "account",
"_id" : "176",
"_score" : 1.0,
"_source" : {
"account_number" : 176,
"balance" : 18607,
"firstname" : "Kemp",
"lastname" : "Walters",
"age" : 28,
"gender" : "F",
"address" : "906 Howard Avenue",
"employer" : "Eyewax",
"email" : "kempwalters@eyewax.com",
"city" : "Why",
"state" : "KY"
}
},
{
"_index" : "bank",
"_type" : "account",
"_id" : "359",
"_score" : 1.0,
"_source" : {
"account_number" : 359,
"balance" : 29927,
"firstname" : "Vanessa",
"lastname" : "Harvey",
"age" : 28,
"gender" : "F",
"address" : "679 Rutledge Street",
"employer" : "Zentime",
"email" : "vanessaharvey@zentime.com",
"city" : "Williston",
"state" : "IL"
}
},
{
"_index" : "bank",
"_type" : "account",
"_id" : "506",
"_score" : 1.0,
"_source" : {
"account_number" : 506,
"balance" : 43440,
"firstname" : "Davidson",
"lastname" : "Salas",
"age" : 28,
"gender" : "M",
"address" : "731 Cleveland Street",
"employer" : "Sequitur",
"email" : "davidsonsalas@sequitur.com",
"city" : "Lloyd",
"state" : "ME"
}
},
{
"_index" : "bank",
"_type" : "account",
"_id" : "669",
"_score" : 1.0,
"_source" : {
"account_number" : 669,
"balance" : 16934,
"firstname" : "Jewel",
"lastname" : "Estrada",
"age" : 28,
"gender" : "M",
"address" : "896 Meeker Avenue",
"employer" : "Zilla",
"email" : "jewelestrada@zilla.com",
"city" : "Goodville",
"state" : "PA"
}
},
{
"_index" : "bank",
"_type" : "account",
"_id" : "708",
"_score" : 1.0,
"_source" : {
"account_number" : 708,
"balance" : 34002,
"firstname" : "May",
"lastname" : "Ortiz",
"age" : 28,
"gender" : "F",
"address" : "244 Chauncey Street",
"employer" : "Syntac",
"email" : "mayortiz@syntac.com",
"city" : "Munjor",
"state" : "ID"
}
},
{
"_index" : "bank",
"_type" : "account",
"_id" : "746",
"_score" : 1.0,
"_source" : {
"account_number" : 746,
"balance" : 15970,
"firstname" : "Marguerite",
"lastname" : "Wall",
"age" : 28,
"gender" : "F",
"address" : "364 Crosby Avenue",
"employer" : "Aquoavo",
"email" : "margueritewall@aquoavo.com",
"city" : "Jeff",
"state" : "MI"
}
},
{
"_index" : "bank",
"_type" : "account",
"_id" : "758",
"_score" : 1.0,
"_source" : {
"account_number" : 758,
"balance" : 15739,
"firstname" : "Berta",
"lastname" : "Short",
"age" : 28,
"gender" : "M",
"address" : "149 Surf Avenue",
"employer" : "Ozean",
"email" : "bertashort@ozean.com",
"city" : "Odessa",
"state" : "UT"
}
}
]
}
}
GET bank/_search
{
"query": {
"term": {
"address": "789 Madison Street"
}
}
}
{
"took" : 0,
"timed_out" : false,
"_shards" : {
"total" : 1,
"successful" : 1,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : {
"value" : 0,
"relation" : "eq"
},
"max_score" : null,
"hits" : [ ]
}
}
GET bank/_search
{
"query": {
"match": {
"address": "789 Madison Street"
}
}
}
{
"took" : 2,
"timed_out" : false,
"_shards" : {
"total" : 1,
"successful" : 1,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : {
"value" : 387,
"relation" : "eq"
},
"max_score" : 12.93561,
"hits" : [
{
"_index" : "bank",
"_type" : "account",
"_id" : "13",
"_score" : 12.93561,
"_source" : {
"account_number" : 13,
"balance" : 32838,
"firstname" : "Nanette",
"lastname" : "Bates",
"age" : 28,
"gender" : "F",
"address" : "789 Madison Street",
"employer" : "Quility",
"email" : "nanettebates@quility.com",
"city" : "Nogal",
"state" : "VA"
}
},
{
"_index" : "bank",
"_type" : "account",
"_id" : "956",
"_score" : 5.9908285,
"_source" : {
"account_number" : 956,
"balance" : 19477,
"firstname" : "Randall",
"lastname" : "Lynch",
"age" : 22,
"gender" : "F",
"address" : "490 Madison Place",
"employer" : "Cosmetex",
"email" : "randalllynch@cosmetex.com",
"city" : "Wells",
"state" : "SD"
}
},
{
"_index" : "bank",
"_type" : "account",
"_id" : "256",
"_score" : 5.9908285,
"_source" : {
"account_number" : 256,
"balance" : 48318,
"firstname" : "Simon",
"lastname" : "Hogan",
"age" : 31,
"gender" : "M",
"address" : "789 Suydam Place",
"employer" : "Dancerity",
"email" : "simonhogan@dancerity.com",
"city" : "Dargan",
"state" : "GA"
}
},
{
"_index" : "bank",
"_type" : "account",
"_id" : "6",
"_score" : 0.95395315,
"_source" : {
"account_number" : 6,
"balance" : 5686,
"firstname" : "Hattie",
"lastname" : "Bond",
"age" : 36,
"gender" : "M",
"address" : "671 Bristol Street",
"employer" : "Netagy",
"email" : "hattiebond@netagy.com",
"city" : "Dante",
"state" : "TN"
}
},
{
"_index" : "bank",
"_type" : "account",
"_id" : "32",
"_score" : 0.95395315,
"_source" : {
"account_number" : 32,
"balance" : 48086,
"firstname" : "Dillard",
"lastname" : "Mcpherson",
"age" : 34,
"gender" : "F",
"address" : "702 Quentin Street",
"employer" : "Quailcom",
"email" : "dillardmcpherson@quailcom.com",
"city" : "Veguita",
"state" : "IN"
}
},
{
"_index" : "bank",
"_type" : "account",
"_id" : "49",
"_score" : 0.95395315,
"_source" : {
"account_number" : 49,
"balance" : 29104,
"firstname" : "Fulton",
"lastname" : "Holt",
"age" : 23,
"gender" : "F",
"address" : "451 Humboldt Street",
"employer" : "Anocha",
"email" : "fultonholt@anocha.com",
"city" : "Sunriver",
"state" : "RI"
}
},
{
"_index" : "bank",
"_type" : "account",
"_id" : "51",
"_score" : 0.95395315,
"_source" : {
"account_number" : 51,
"balance" : 14097,
"firstname" : "Burton",
"lastname" : "Meyers",
"age" : 31,
"gender" : "F",
"address" : "334 River Street",
"employer" : "Bezal",
"email" : "burtonmeyers@bezal.com",
"city" : "Jacksonburg",
"state" : "MO"
}
},
{
"_index" : "bank",
"_type" : "account",
"_id" : "63",
"_score" : 0.95395315,
"_source" : {
"account_number" : 63,
"balance" : 6077,
"firstname" : "Hughes",
"lastname" : "Owens",
"age" : 30,
"gender" : "F",
"address" : "510 Sedgwick Street",
"employer" : "Valpreal",
"email" : "hughesowens@valpreal.com",
"city" : "Guilford",
"state" : "KS"
}
},
{
"_index" : "bank",
"_type" : "account",
"_id" : "87",
"_score" : 0.95395315,
"_source" : {
"account_number" : 87,
"balance" : 1133,
"firstname" : "Hewitt",
"lastname" : "Kidd",
"age" : 22,
"gender" : "M",
"address" : "446 Halleck Street",
"employer" : "Isologics",
"email" : "hewittkidd@isologics.com",
"city" : "Coalmont",
"state" : "ME"
}
},
{
"_index" : "bank",
"_type" : "account",
"_id" : "107",
"_score" : 0.95395315,
"_source" : {
"account_number" : 107,
"balance" : 48844,
"firstname" : "Randi",
"lastname" : "Rich",
"age" : 28,
"gender" : "M",
"address" : "694 Jefferson Street",
"employer" : "Netplax",
"email" : "randirich@netplax.com",
"city" : "Bellfountain",
"state" : "SC"
}
}
]
}
}
##精确匹配
GET bank/_search
{
"query": {
"match": {
"address.keyword": "789 Madison"
}
}
}
{
"took" : 0,
"timed_out" : false,
"_shards" : {
"total" : 1,
"successful" : 1,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : {
"value" : 0,
"relation" : "eq"
},
"max_score" : null,
"hits" : [ ]
}
}
GET bank/_search
{
"query": {
"match_phrase": {
"address": "789 Madison"
}
}
}
{
"took" : 0,
"timed_out" : false,
"_shards" : {
"total" : 1,
"successful" : 1,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : {
"value" : 1,
"relation" : "eq"
},
"max_score" : 11.981657,
"hits" : [
{
"_index" : "bank",
"_type" : "account",
"_id" : "13",
"_score" : 11.981657,
"_source" : {
"account_number" : 13,
"balance" : 32838,
"firstname" : "Nanette",
"lastname" : "Bates",
"age" : 28,
"gender" : "F",
"address" : "789 Madison Street",
"employer" : "Quility",
"email" : "nanettebates@quility.com",
"city" : "Nogal",
"state" : "VA"
}
}
]
}
}
全文检索字段用match,其他非text字段匹配用term