世界上并没有完美的程序,但是我们并不因此而沮丧,因为写程序就是一个不断追求完美的过程。
问:span_multi有什么特点?
答:
问:span_multi如何使用?
答:
# span_multi
PUT /span_multi_test
{
"mappings": {
"properties": {
"name": {
"type" : "text",
"fields": {
"eng": {
"type" : "text",
"analyzer": "english"
}
}
},
"age": {
"type": "text"
}
}
}
}
# 索引
POST /span_multi_test/_doc/1
{
"name": "hello good me foxes",
"age" : "18"
}
# 索引
POST /span_multi_test/_doc/2
{
"name": "hello1 good me",
"age" : "28"
}
# 索引
POST /span_multi_test/_doc/3
{
"name": "hello1 good1 foxes me",
"age" : "58"
}
# 索引
POST /span_multi_test/_doc/4
{
"name": "hello1 good1 me1",
"age" : "88"
}
# 索引
POST /span_multi_test/_doc/5
{
"name": "hello1 foxes good me1",
"age" : "66"
}
# 搜索
GET /span_multi_test/_search
{
"query": {
"span_multi": {
"match": {
"prefix": {
"name.eng": {
"value": "fo"
}
}
}
}
}
}
# 结果
{
"took" : 10,
"timed_out" : false,
"_shards" : {
"total" : 1,
"successful" : 1,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : {
"value" : 3,
"relation" : "eq"
},
"max_score" : 0.42599016,
"hits" : [
{
"_index" : "span_multi_test",
"_type" : "_doc",
"_id" : "1",
"_score" : 0.42599016,
"_source" : {
"name" : "hello good me foxes",
"age" : "18"
}
},
{
"_index" : "span_multi_test",
"_type" : "_doc",
"_id" : "3",
"_score" : 0.42599016,
"_source" : {
"name" : "hello1 good1 foxes me",
"age" : "58"
}
},
{
"_index" : "span_multi_test",
"_type" : "_doc",
"_id" : "5",
"_score" : 0.42599016,
"_source" : {
"name" : "hello1 foxes good me1",
"age" : "66"
}
}
]
}
}
# 搜索
GET /span_multi_test/_search
{
"query": {
"span_multi": {
"match": {
"wildcard": {
"name": {
"value": "goo*"
}
}
}
}
}
}
# 结果
{
"took" : 0,
"timed_out" : false,
"_shards" : {
"total" : 1,
"successful" : 1,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : {
"value" : 5,
"relation" : "eq"
},
"max_score" : 1.5896939,
"hits" : [
{
"_index" : "span_multi_test",
"_type" : "_doc",
"_id" : "2",
"_score" : 1.5896939,
"_source" : {
"name" : "hello1 good me",
"age" : "28"
}
},
{
"_index" : "span_multi_test",
"_type" : "_doc",
"_id" : "4",
"_score" : 1.5896939,
"_source" : {
"name" : "hello1 good1 me1",
"age" : "88"
}
},
{
"_index" : "span_multi_test",
"_type" : "_doc",
"_id" : "1",
"_score" : 1.418691,
"_source" : {
"name" : "hello good me foxes",
"age" : "18"
}
},
{
"_index" : "span_multi_test",
"_type" : "_doc",
"_id" : "3",
"_score" : 1.418691,
"_source" : {
"name" : "hello1 good1 foxes me",
"age" : "58"
}
},
{
"_index" : "span_multi_test",
"_type" : "_doc",
"_id" : "5",
"_score" : 1.418691,
"_source" : {
"name" : "hello1 foxes good me1",
"age" : "66"
}
}
]
}
}
# 搜索
GET /span_multi_test/_search
{
"query": {
"span_multi": {
"match": {
"fuzzy": {
"name": {
"value" : "he",
"fuzziness": 5
}
}
}
}
}
}
# 结果
{
"took" : 10,
"timed_out" : false,
"_shards" : {
"total" : 1,
"successful" : 1,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : {
"value" : 5,
"relation" : "eq"
},
"max_score" : 1.497693,
"hits" : [
{
"_index" : "span_multi_test",
"_type" : "_doc",
"_id" : "2",
"_score" : 1.497693,
"_source" : {
"name" : "hello1 good me",
"age" : "28"
}
},
{
"_index" : "span_multi_test",
"_type" : "_doc",
"_id" : "4",
"_score" : 1.497693,
"_source" : {
"name" : "hello1 good1 me1",
"age" : "88"
}
},
{
"_index" : "span_multi_test",
"_type" : "_doc",
"_id" : "1",
"_score" : 1.3365866,
"_source" : {
"name" : "hello good me foxes",
"age" : "18"
}
},
{
"_index" : "span_multi_test",
"_type" : "_doc",
"_id" : "3",
"_score" : 1.3365866,
"_source" : {
"name" : "hello1 good1 foxes me",
"age" : "58"
}
},
{
"_index" : "span_multi_test",
"_type" : "_doc",
"_id" : "5",
"_score" : 1.3365866,
"_source" : {
"name" : "hello1 foxes good me1",
"age" : "66"
}
}
]
}
}
# 搜索
GET /span_multi_test/_search
{
"query": {
"span_multi": {
"match": {
"range": {
"age": {
"gte": 10,
"lte": 77
}
}
}
}
}
}
# 结果
{
"took" : 0,
"timed_out" : false,
"_shards" : {
"total" : 1,
"successful" : 1,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : {
"value" : 4,
"relation" : "eq"
},
"max_score" : 5.6509542,
"hits" : [
{
"_index" : "span_multi_test",
"_type" : "_doc",
"_id" : "1",
"_score" : 5.6509542,
"_source" : {
"name" : "hello good me foxes",
"age" : "18"
}
},
{
"_index" : "span_multi_test",
"_type" : "_doc",
"_id" : "2",
"_score" : 5.6509542,
"_source" : {
"name" : "hello1 good me",
"age" : "28"
}
},
{
"_index" : "span_multi_test",
"_type" : "_doc",
"_id" : "3",
"_score" : 5.6509542,
"_source" : {
"name" : "hello1 good1 foxes me",
"age" : "58"
}
},
{
"_index" : "span_multi_test",
"_type" : "_doc",
"_id" : "5",
"_score" : 5.6509542,
"_source" : {
"name" : "hello1 foxes good me1",
"age" : "66"
}
}
]
}
}
# 搜索
GET /span_multi_test/_search
{
"query": {
"span_multi": {
"match": {
"regexp": {
"age": "[0-9]{2}"
}
}
}
}
}
# 结果
{
"took" : 0,
"timed_out" : false,
"_shards" : {
"total" : 1,
"successful" : 1,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : {
"value" : 5,
"relation" : "eq"
},
"max_score" : 7.1913996,
"hits" : [
{
"_index" : "span_multi_test",
"_type" : "_doc",
"_id" : "1",
"_score" : 7.1913996,
"_source" : {
"name" : "hello good me foxes",
"age" : "18"
}
},
{
"_index" : "span_multi_test",
"_type" : "_doc",
"_id" : "2",
"_score" : 7.1913996,
"_source" : {
"name" : "hello1 good me",
"age" : "28"
}
},
{
"_index" : "span_multi_test",
"_type" : "_doc",
"_id" : "3",
"_score" : 7.1913996,
"_source" : {
"name" : "hello1 good1 foxes me",
"age" : "58"
}
},
{
"_index" : "span_multi_test",
"_type" : "_doc",
"_id" : "4",
"_score" : 7.1913996,
"_source" : {
"name" : "hello1 good1 me1",
"age" : "88"
}
},
{
"_index" : "span_multi_test",
"_type" : "_doc",
"_id" : "5",
"_score" : 7.1913996,
"_source" : {
"name" : "hello1 foxes good me1",
"age" : "66"
}
}
]
}
}