elasticsearch 查询:term&terms
1. term查询
term查询:完全匹配查询,搜索前不会对关键字进行分词。
只支持单个feild查询。
不设置 from,size。默认返回10条
#测试--term查询 POST /king_test_person/_search { "from": 0, # limit ? "size": 20, # limit x,? "query": { "term": { "name": { "value": "王五" } } } }
2. terms 查询
terms和term查询机制是一样的,都不会对指定关键字进行分词,直接去分词库中匹配,找到相应的文档内容。
terms是针对一个字段包含多个值的时候使用。
term:where name = 张三
terms:where name = 张三 or name = 李四 or name = 王五
#测试--terms查询 POST /king_test_person/_search { "query": { "terms": { "name": [ "王五", "王麻子" ] } } }