1.ES 插数据
curl -XPOST http://localhost:9200/index/file_flow -d ''
2.ES过滤掉log_value为3的数据并排序
curl localhost:9200/index/_search?pretty -d '{"query":{"bool":{"must_not":{"match":{"log_value":3}}}},"sort":[{"create_time":"desc"}]}'
3.查看ES某个索引下的数据总数
curl localhost:9200/index/_count
4.查看某个索引下按时间倒排前1000条
curl localhost:9200/index/_search?pretty -d '{"query":{"match_all":{}},"sort":[{"create_time":"desc"}],"size":1000}'
curl localhost:9200/index/_search?pretty -d '{"query":{"term":{"log_value":0}}}'
term用法
先看看term的定义,term是代表完全匹配,也就是精确查询,搜索前不会再对搜索词进行分词拆解。
term只能查单个单词;
多个单词匹配时可以用terms,{"query":{"terms":{"log_type":["a","b"]}}}匹配时A、B是或的关系
如果想要精确匹配a b
{"query":{"bool":{"must":[{"term":{"title":"a"}},{"term":{"title":"b"}}]}}}
match的用法
match进行搜索的时候,会先进行分词拆分,match匹配两个字符时,先进行分词拆分,
{"query":{"match":{"log_type":"a b"}}} 匹配分词A或B,log_type的词条为:a b ,我们搜索的为a b 我们进行分词处理得到为a b,并且属于或的关系,只要任何一个词条在里面就能匹配到
match_phrase 用法
为短语搜索,要求所有的分词必须同时出现在文档中,同时位置必须紧邻一致
{"query":{"match_phrase":{"log_type":"a b"}}}