Continue from section 15
8)、term
Same as match. Match the value of an attribute. 全文检索字段用 match,其他非 text 字段匹配用 term
.
Avoid using the
term
query fortext
fields.By default, Elasticsearch changes the values of
text
fields as part of analysis. This can make finding exact matches fortext
field values difficult.To search
text
field values, use thematch
query instead.
Non-text values are retrieved using term:
GET /bank/_search
{
"query": {
"term": {
"age":28
}
}
}
match xxx.keyword
, search for exact match of text:
GET /bank/_search
{
"query": {
"match": {
"address.keyword": "789 Madison"
}
}
}
match Full text word segmentation matching:
GET /bank/_search
{
"query": {
"match": {
"address": "789 Madison"
}
}
}
match_phrase, to retrieve the value to be matched as a whole word (no word segmentation):
GET /bank/_search
{
"query": {
"match_phrase": {
"address": "789 Madison"
}
}
}
注意
: If you use term to search for text values, the word segmentation will not be performed, but the exact search will be performed, so the data may not be matched:
GET /bank/_search
{
"query": {
"term": {
"address": "789 Madison"
}
}
}
reference:
Getting started with the full-text search engine Elasticsearch