I have read the docs,Term query | Elasticsearch Guide [8.0] | Elastic
I know that the text field should not be queried with term.
But there's another sentence in the document
The
term
query does not analyze the search term. Theterm
query only searches for the exact term you provide. This means theterm
query may return poor or no results when searchingtext
fields.
I wonder why I can't query text by term, because in my example below, I've already segmented text
My index template is as follows
{
"order": 0,
"index_patterns": [
"resource*",
"resource-dev*"
],
"settings": {
"index": {
"number_of_shards": "6",
"number_of_replicas": "1",
"refresh_interval": "200ms"
}
},
"mappings": {
"dynamic_templates": [
{
"strings": {
"mapping": {
"type": "keyword"
},
"match_mapping_type": "string"
}
}
],
"properties": {
"id": {
"type": "keyword"
},
"almScode": {
"type": "keyword"
},
"name": {
"type": "keyword"
},
"desc": {
"type": "text"
},
"parentId": {
"type": "keyword"
},
"fullId": {
"type": "text",
"analyzer": "pattern",
"fields": {
"raw": {
"type": "keyword"
}
}
},
"type": {
"type": "keyword"
},
"attrs": {
"type": "object"
},
"creator": {
"type": "keyword"
},
"updater": {
"type": "keyword"
},
"createdAt": {
"format": "epoch_second",
"type": "date"
},
"updatedAt": {
"format": "epoch_second",
"type": "date"
}
}
}
}
The document format is as follows
{
"id" : "jiankunking_hdyst_modeProgress",
"almScode" : "jiankunking",
"name" : "hdyst_modeProgress",
"desc" : "新品型号进度界面",
"parentId" : "jiankunking_hdyst_root",
"fullId" : "hdyst_root.hdyst_modeProgress",
"type" : "menu",
"attrs" : {
"path" : {
"attrValue" : "/hdy/modeProgress",
"attrType" : "String",
"attrDesc" : "菜单路径"
},
"sort" : {
"attrValue" : "5",
"attrType" : "String",
"attrDesc" : "排序"
}
},
"creator" : "jiankunking",
"updater" : "jiankunking",
"createdAt" : 1646130169,
"updatedAt" : 0,
"updateAt" : 1646130169
}
We need to pay attention to the fullId field。
I looked at the segmentation results by vectors _termvectors:
#! [types removal] Specifying types in term vector requests is deprecated.
{
"_index" : "resource-dev-new2-jiankunking",
"_type" : "_doc",
"_id" : "jiankunking_hdyst_modeProgress",
"_version" : 1,
"found" : true,
"took" : 7,
"term_vectors" : {
"fullId" : {
"field_statistics" : {
"sum_doc_freq" : 932,
"doc_count" : 244,
"sum_ttf" : 932
},
"terms" : {
"hdyst_modeprogress" : {
"term_freq" : 1,
"tokens" : [
{
"position" : 1,
"start_offset" : 11,
"end_offset" : 29
}
]
},
"hdyst_root" : {
"term_freq" : 1,
"tokens" : [
{
"position" : 0,
"start_offset" : 0,
"end_offset" : 10
}
]
}
}
}
}
}
My question is why doc cannot be queried through the following query statement
GET /resource-dev-jiankunking/_search
{
"size": 2000,
"query": {
"bool": {
"filter": [
{
"terms": {
"fullId": [
"hdyst_modeProgress"
]
}
}
]
}
}
}