世界上并没有完美的程序,但是我们并不因此而沮丧,因为写程序就是一个不断追求完美的过程。
问:intervals有什么特点?
答:
问:intervals如何使用?
答:
# intervals
# 映射
PUT /intervals_1_test
{"mappings": {"properties": {"name": {"type": "text"},"num" : {"type": "integer"}}}
}# 索引
POST /intervals_1_test/_doc/1
{"name": "hello","num" : 1
}# 索引
POST /intervals_1_test/_doc/2
{"name": "hello good","num" : 100
}# 索引
POST /intervals_1_test/_doc/3
{"name": "good hello","num" : 5
}# 索引
POST /intervals_1_test/_doc/4
{"name": "hello hello","num" : 10
}# 搜索 - 普通匹配
GET /intervals_1_test/_search
{"query": {"match": {"name": "hello"}}
}# 结果
{"took" : 10,"timed_out" : false,"_shards" : {"total" : 1,"successful" : 1,"skipped" : 0,"failed" : 0},"hits" : {"total" : {"value" : 4,"relation" : "eq"},"max_score" : 0.09935807,"hits" : [{"_index" : "intervals_1_test","_type" : "_doc","_id" : "4","_score" : 0.09935807,"_source" : {"name" : "hello hello","num" : 10}},{"_index" : "intervals_1_test","_type" : "_doc","_id" : "1","_score" : 0.0910362,"_source" : {"name" : "hello","num" : 1}},{"_index" : "intervals_1_test","_type" : "_doc","_id" : "2","_score" : 0.07145072,"_source" : {"name" : "hello good","num" : 100}},{"_index" : "intervals_1_test","_type" : "_doc","_id" : "3","_score" : 0.07145072,"_source" : {"name" : "good hello","num" : 5}}]}
}# 搜索 - match
GET /intervals_1_test/_search
{"query": {"intervals": {"name": {"all_of": {"ordered" : true,"intervals": [{"match": {"query" : "hello","max_gaps": 0,"ordered" : true,"analyzer": "standard","filter" : {"not_containing": {"match": {"query": "key"}}}}},{"any_of": {"intervals": [{"match": {"query": "good"}}]}}]}}}}
}# 结果
{"took" : 0,"timed_out" : false,"_shards" : {"total" : 1,"successful" : 1,"skipped" : 0,"failed" : 0},"hits" : {"total" : {"value" : 1,"relation" : "eq"},"max_score" : 0.5,"hits" : [{"_index" : "intervals_1_test","_type" : "_doc","_id" : "2","_score" : 0.5,"_source" : {"name" : "hello good","num" : 100}}]}
}# 搜索 - prefix wildcard
GET /intervals_1_test/_search
{"query": {"intervals": {"name": {"all_of": {"ordered" : true,"intervals": [{"prefix": { "prefix": "he" }},{"wildcard": { "pattern": "hell*" }}]}}}}
}# 结果
{"took" : 0,"timed_out" : false,"_shards" : {"total" : 1,"successful" : 1,"skipped" : 0,"failed" : 0},"hits" : {"total" : {"value" : 1,"relation" : "eq"},"max_score" : 0.5,"hits" : [{"_index" : "intervals_1_test","_type" : "_doc","_id" : "4","_score" : 0.5,"_source" : {"name" : "hello hello","num" : 10}}]}
}# 搜索 - fuzzy
GET /intervals_1_test/_search
{"query": {"intervals": {"name": {"all_of": {"intervals": [{"fuzzy": {"term": "good"}}],"filter": {"after": {"prefix": {"prefix": "hello"}}}}}}}
}# 结果
{"took" : 1,"timed_out" : false,"_shards" : {"total" : 1,"successful" : 1,"skipped" : 0,"failed" : 0},"hits" : {"total" : {"value" : 1,"relation" : "eq"},"max_score" : 0.5,"hits" : [{"_index" : "intervals_1_test","_type" : "_doc","_id" : "2","_score" : 0.5,"_source" : {"name" : "hello good","num" : 100}}]}
}