标签:不同的 source phrase 精确 setting ica 插入 res ast
term查询查找包含文档精确的倒排索引指定的词条。也就是精确查找(没经过分词)。
term和match的区别是:
match是经过analyer的,也就是说,文档首先被分析器给处理了。根据不同的分析器,分析的结果也稍显不同,然后再根据分词结果进行匹配。
term则不经过分词,它是直接去倒排索引中查找了精确的值了。
建立数据结构
PUT w1 { "mappings": { "doc": { "properties":{ "t1":{ "type": "text" }, "t2": { "type": "keyword" } } } } } PUT w1/doc/1 { "t1": "hi single dog", "t2": "hi single dog" }
GET w1/doc/_search { "query": { "term": { "t1": "hi" } } }
#能查到
GET w1/doc/_search { "query": { "term": { "t2": "hi" } } }
#查不到
GET w1/doc/_search { "query": { "match": { "t2": "hi single dog" } } }
#只能这样查询keyword的值
GET w1/doc/_search { "query": { "match": { "t1": "hi" } } }
#t1 进行了分词,可以查到
①原样式
PUT w1/doc/2 { "t1": "20", "t2": "2019-4-16" } PUT w1/doc/3 { "t1": "30", "t2": "2019-4-17" } GET w1/doc/_search { "query": { "bool": { "should": [ { "term": { "t1": "20" } }, { "term": { "t1": "30" } } ] } } }
②简单样式
GET w1/doc/_search { "query": { "terms": { "t1": ["20", "30"] } } } GET w1/doc/_search { "query": { "terms": { "t2": ["2019-4-16", "2019-4-17"] } } }
两种顺序都可以得到结果
GET c12/doc/_search { "suggest": { "text": "appl", #要修改词 "my1": { #别名 "term": { "field": "title" #对照字段 } } } }
GET c12/doc/_search { "suggest": { "my1": { #别名 "text": "appl", "term": { "field": "title" } } } }
GET s1/doc/_search { "suggest": { "my_s1": { "text": "luce is coo", "phrase": { "field": "title" } } } }
加高亮显示
GET s4/doc/_search { "suggest": { "my_s4": { "text": "lucen elasticsearc rock", "phrase": { "field": "title", "highlight":{ "pre_tag":"<em class=‘xxx‘>", "post_tag":"</em>" } } } } }
GET s8/doc/_search { "suggest": { "s3": { "text": "bl", "completion": { "field": "title" } } } }
修改器和建议器一起用
GET c12/doc/_search { "suggest": { "text": "appl", "s1": { "term": { "field": "title" } }, "s2": { "phrase": { "field": "title" } }, "s3": { "completion": { "field": "title" } } } }
建立数据结构
PUT s8 { "mappings": { "doc":{ "properties":{ "title":{ "type": "completion" } } } } }
插入数据
PUT s8/doc/3 { "title": [ { "input":"appel", "weight": 2 }, { "input":"apple", "weight": 3 } ] }
查询
GET s8/doc/_search { "suggest": { "my_s8": { "text": "app", "completion": { "field": "title" } } } }
GET s8/doc/_search { "suggest": { "completion_suggest": { "prefix": "app", "completion": { "field": "title", "size": 1 } } }, "_source": "title"
GET s8/doc/_search { "suggest": { "completion_suggest": { "prefix": "app", "completion": { "field": "title", "size": 5, "skip_duplicates":true } } }, "_source": "title" }
进行修改
PUT s18/_settings { "index":{ "max_result_window": "11000" } }
这样就可以返回10000以上的数据量了
GET s18/doc/_search { "size": 11000, "query": { "match_all": {} } }
Elasticsearch --- 4. term与match ,修改器,建议器
标签:不同的 source phrase 精确 setting ica 插入 res ast
原文地址:https://www.cnblogs.com/sc-1067178406/p/10920414.html