term(词条)查询和full text(全文)查询
词条查询:词条查询不会分析查询条件,只有词条和查询字符串完全匹配时,才匹配搜索。
全文查询:Elasticsearch引擎会先分析查询字符串,将其拆分成多个分词,只要已分析的字段中包含词条的任意一个,或全部包含,就匹配查询条件,返回该文档;如果不包含任意一个分词,表示没有任何文档匹配查询条件。
POST localhost:9200/nba/_search
term查询
单条term查询
条件:jerse_no为23
{
"query":{
"term":{
"jerse_no":"23"
}
}
}
多条term查询
条件:jerse_no为23或者13
{
"query": {
"terms": {
"jerse_no": ["23","13"]
}
}
}
full Text 查询
match_all
条件:无
数量:从第0条开始,最大10条数据
{
"query": {
"match_all": {}
},
"from": 0,
"size": 10
}
match
条件:position含有“后卫”(包含任意一个即可匹配)
{
"query": {
"match": {
"position": "后卫"
}
}
}
multi_match
条件:title或者name含有“shooter”
{
"query": {
"multi_match": {
"query":"shooter",
"fields":["title","name"]
}
}
}
条件:title或者name含有“shooter”
{
"query": {
"multi_match": {
"query":"shooter",
"fields":["*title","*name"]
}
}
}
match_phrase
条件:position包含完整“得分后卫”
{
"query": {
"match_phrase": {
"position":"得分后卫"
}
}
}
match_phrase_prefix
条件:title包含完整“the best s”(前后可以有其他字符)
{
"query": {
"match_phrase_prefix": {
"title":"the best s"
}
}
}