最新《孔令傑用Python做商管程式設計(一)》
作者:互联网
// 1.
GET http://ip:9200/test/test/_search
结果:
{
"took": 86, # 耗费的时间:ms
"timed_out": false, # 是否超时
"_shards": { # 数据存储在5个主分片上
"total": 5,
"successful": 5,
"skipped": 0,
"failed": 0
},
"hits": { # 匹配结果
"total": 3, # 查询到三个document
"max_score": 1, # 相关度的匹配分数:分数越高越相关
"hits": [
{
"_index": "test", # 索引 index
"_type": "test", # type
"_id": "2", # id:唯一
"_score": 1, # 相关度的匹配分数:分数越高越相关
"_source": { # 存储的json数据
"first_name": "小翠", # field
"last_name": "cuicui",
"age": 18,
"about": "I love to go rock climbing",
"interests": [
"sports",
"music"
]
}
},
{
"_index": "test",
"_type": "test",
"_id": "1",
"_score": 1,
"_source": {
"first_name": "John",
"last_name": "Smith",
"age": 25,
"about": "I love to go rock climbing",
"interests": [
"sports",
"music"
]
}
},
{
"_index": "test",
"_type": "test",
"_id": "AWrVpGsO0WDJvaOeQOjd",
"_score": 1,
"_source": {
"first_name": "小翠",
"last_name": "cui",
"age": 18,
"about": "I love to go rock climbing",
"interests": [
"sports",
"music"
]
}
}
]
}
}
// 2.
GET http://ip:9200/test/test/_search?q=about:climbing&sort=age:desc,price:desc
GET http://ip:9200/test/test/_search?q=about:climbing&sort=age:desc
{
"took": 10,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"skipped": 0,
"failed": 0
},
"hits": {
"total": 3,
"max_score": null,
"hits": [
{
"_index": "test",
"_type": "test",
"_id": "1",
"_score": null,
"_source": {
"first_name": "John",
"last_name": "Smith",
"age": 25,
"about": "I love to go rock climbing",
"interests": [
"sports",
"music"
]
},
"sort": [ #排序字段的值
25
]
},
{
"_index": "test",
"_type": "test",
"_id": "2",
"_score": null,
"_source": {
"first_name": "小翠",
"last_name": "cuicui",
"age": 18,
"about": "I love to go rock climbing",
"interests": [
"sports",
"music"
]
},
"sort": [
18
]
},
{
"_index": "test",
"_type": "test",
"_id": "AWrVpGsO0WDJvaOeQOjd",
"_score": null,
"_source": {
"first_name": "小翠",
"last_name": "cui",
"age": 18,
"about": "I love to go rock climbing",
"interests": [
"sports",
"music"
]
},
"sort": [
18
]
}
]
}
}
// 1.
POST http://ip:9200/test/test/_search
语法:
{
"query":{
"match_all":{}
}
}
结果:
{
"took": 5,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"skipped": 0,
"failed": 0
},
"hits": {
"total": 5,
"max_score": 1,
"hits": [
{
"_index": "test",
"_type": "test",
"_id": "2",
"_score": 1,
"_source": {
"first_name": "小翠",
"last_name": "cuicui",
"age": 18,
"about": "I love to go rock climbing",
"interests": [
"sports",
"music"
]
}
},
{
"_index": "test",
"_type": "test",
"_id": "4",
"_score": 1,
"_source": {
"first_name": "小翠",
"last_name": "cui",
"age": 18,
"price": 15000,
"about": "I love to go rock climbing",
"interests": [
"sports",
"music"
]
}
},
{
"_index": "test",
"_type": "test",
"_id": "1",
"_score": 1,
"_source": {
"first_name": "John",
"last_name": "Smith",
"age": 25,
"about": "I love to go rock climbing",
"interests": [
"sports",
"music"
]
}
},
{
"_index": "test",
"_type": "test",
"_id": "AWrVpGsO0WDJvaOeQOjd",
"_score": 1,
"_source": {
"first_name": "小翠",
"last_name": "cui",
"age": 18,
"about": "I love to go rock climbing",
"interests": [
"sports",
"music"
]
}
},
{
"_index": "test",
"_type": "test",
"_id": "3",
"_score": 1,
"_source": {
"first_name": "小雪",
"last_name": "xiaoxue",
"age": 20,
"about": "climbing",
"interests": [
"dancing",
"music"
]
}
}
]
}
}
// 1.
POST http://ip:9200/test/test/_search
语法:
{
"query":{
"match":{
"about":"climbing"
}
},
"sort":[
{
"age":"desc"
}
]
}
结果:
{
"took": 115,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"skipped": 0,
"failed": 0
},
"hits": {
"total": 5,
"max_score": null,
"hits": [
{
"_index": "test",
"_type": "test",
"_id": "1",
"_score": null,
"_source": {
"first_name": "John",
"last_name": "Smith",
"age": 25,
"about": "I love to go rock climbing",
"interests": [
"sports",
"music"
]
},
"sort": [
25
]
},
{
"_index": "test",
"_type": "test",
"_id": "3",
"_score": null,
"_source": {
"first_name": "小雪",
"last_name": "xiaoxue",
"age": 20,
"about": "climbing",
"interests": [
"dancing",
"music"
]
},
"sort": [
20
]
},
{
"_index": "test",
"_type": "test",
"_id": "2",
"_score": null,
"_source": {
"first_name": "小翠",
"last_name": "cuicui",
"age": 18,
"about": "I love to go rock climbing",
"interests": [
"sports",
"music"
]
},
"sort": [
18
]
},
{
"_index": "test",
"_type": "test",
"_id": "4",
"_score": null,
"_source": {
"first_name": "小翠",
"last_name": "cui",
"age": 18,
"price": 15000,
"about": "I love to go rock climbing",
"interests": [
"sports",
"music"
]
},
"sort": [
18
]
},
{
"_index": "test",
"_type": "test",
"_id": "AWrVpGsO0WDJvaOeQOjd",
"_score": null,
"_source": {
"first_name": "小翠",
"last_name": "cui",
"age": 18,
"about": "I love to go rock climbing",
"interests": [
"sports",
"music"
]
},
"sort": [
18
]
}
]
}
}
// 1.
POST http://ip:9200/test/test/_search
语法:
{
"query":{
"bool":{
"must":{
"match":{
"about":"climbing"
}
},
"filter":{
"range":{
"age":{
"gt":20
}
}
}
}
}
}
结果
{
"took": 7,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"skipped": 0,
"failed": 0
},
"hits": {
"total": 1,
"max_score": 0.26742277,
"hits": [
{
"_index": "test",
"_type": "test",
"_id": "1",
"_score": 0.26742277,
"_source": {
"first_name": "John",
"last_name": "Smith",
"age": 25,
"about": "I love to go rock climbing",
"interests": [
"sports",
"music"
]
}
}
]
}
}
POST http://ip:9200/test/test/_search
{
"query":{
"bool":{
"must":{ # 必须匹配
"match":{
"first_name":"小翠"
}
},
"should":{ # 可以匹配,也可以不匹配
"match":{
"last_name": "xue"
}
},
"must_not":{ # 必须不匹配
"match":{
"last_name": "cui"
}
}
}
}
}
// 1.
POST http://ip:9200/test/test/_search
语法:
{
"query":{
"match":{
"about":"go climbing"
}
}
}
分析:es将about这个filed拆解成每个词(term),建立倒排索引,每个term对应相应的document_id
结果:
{
"took": 8,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"skipped": 0,
"failed": 0
},
"hits": {
"total": 7,
"max_score": 0.7447149,
"hits": [
{
"_index": "test",
"_type": "test",
"_id": "2",
"_score": 0.7447149,
"_source": {
"first_name": "小翠",
"last_name": "cuicui",
"age": 18,
"about": "I love to go rock climbing",
"interests": [
"sports",
"music"
]
}
},
{
"_index": "test",
"_type": "test",
"_id": "4",
"_score": 0.7447149,
"_source": {
"first_name": "小翠",
"last_name": "cui",
"age": 18,
"price": 15000,
"about": "I love to go rock climbing",
"interests": [
"sports",
"music"
]
}
},
{
"_index": "test",
"_type": "test",
"_id": "1",
"_score": 0.61562645,
"_source": {
"first_name": "John",
"last_name": "Smith",
"age": 25,
"about": "I love to go rock climbing",
"interests": [
"sports",
"music"
]
}
},
{
"_index": "test",
"_type": "test",
"_id": "AWrVpGsO0WDJvaOeQOjd",
"_score": 0.61562645,
"_source": {
"first_name": "小翠",
"last_name": "cui",
"age": 18,
"about": "I love to go rock climbing",
"interests": [
"sports",
"music"
]
}
},
{
"_index": "test",
"_type": "test",
"_id": "5",
"_score": 0.2876821,
"_source": {
"first_name": "花花",
"last_name": "huahau",
"age": 16,
"price": 20000,
"about": "climbing",
"interests": [
"sports",
"music"
]
}
},
{
"_index": "test",
"_type": "test",
"_id": "7",
"_score": 0.25759193,
"_source": {
"about": "go"
}
},
{
"_index": "test",
"_type": "test",
"_id": "3",
"_score": 0.25759193,
"_source": {
"first_name": "小雪",
"last_name": "xiaoxue",
"age": 20,
"about": "climbing",
"interests": [
"dancing",
"music"
]
}
}
]
}
}
// 1.
POST http://ip:9200/test/test/_search
语法:
{
"query":{
"match_phrase":{
"about":"rock climbing"
}
}
}
结果:
{
"took": 20,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"skipped": 0,
"failed": 0
},
"hits": {
"total": 4,
"max_score": 0.9748371,
"hits": [
{
"_index": "test",
"_type": "test",
"_id": "1",
"_score": 0.9748371,
"_source": {
"first_name": "John",
"last_name": "Smith",
"age": 25,
"about": "I love to go rock climbing",
"interests": [
"sports",
"music"
]
}
},
{
"_index": "test",
"_type": "test",
"_id": "2",
"_score": 0.7447149,
"_source": {
"first_name": "小翠",
"last_name": "cuicui",
"age": 18,
"about": "I love to go rock climbing",
"interests": [
"sports",
"music"
]
}
},
{
"_index": "test",
"_type": "test",
"_id": "4",
"_score": 0.7447149,
"_source": {
"first_name": "小翠",
"last_name": "cui",
"age": 18,
"price": 15000,
"about": "I love to go rock climbing",
"interests": [
"sports",
"music"
]
}
},
{
"_index": "test",
"_type": "test",
"_id": "AWrVpGsO0WDJvaOeQOjd",
"_score": 0.6156264,
"_source": {
"first_name": "小翠",
"last_name": "cui",
"age": 18,
"about": "I love to go rock climbing",
"interests": [
"sports",
"music"
]
}
}
]
}
}
标签:about,name,Python,age,設計,商管,score,test,climbing 来源: https://blog.csdn.net/qq_18258267/article/details/94881290