我有一個簡單的檔案,其中 _source 看起來像:
{
"name" : "myProduct",
"label" : "isApiisApi",
"isApi" : 1,
"sold" : 0
}
我一直在嘗試使用 bool 創建一個多條件查詢。我讓它作業的唯一方法是使用匹配查詢:
{
"query": {
"bool": {
"must": [
{ "term": { "sold": 0 } },
{ "term": { "isApi": 1 } },
{ "match": { "name": "myProduct" } }
]
}
}
}
但是為什么當我使用術語查詢時它不起作用(作為最終條件):
{
"query": {
"bool": {
"must": [
{ "term": { "sold": 0 } },
{ "term": { "isApi": 1 } },
{ "term": { "name": "myProduct" } }
]
}
}
}
uj5u.com熱心網友回復:
特長;
攝取時的彈性文本欄位將資料傳遞到分析器中。
默認情況下使用標準分析器。它帶有一個名為Lowercase的令牌過濾器。
您的文本以小寫字母編入索引。
但是您使用的是在索引資料上搜索完全匹配的術語。
在你的情況下myproduct=/= myProduct。
重現
默認情況下,彈性索引,兩個欄位中的所有類似資料的字串。
textkeyword
對于完全匹配,您要使用關鍵字版本。
見下文:
POST /72020272/_doc
{
"name" : "myProduct",
"label" : "isApiisApi",
"isApi" : 1,
"sold" : 0
}
GET /72020272/_mapping
GET /72020272/_search
{
"query": {
"bool": {
"must": [
{ "term": { "sold": 0 } },
{ "term": { "isApi": 1 } },
{ "term": { "name": "myProduct" } }
]
}
}
}
GET /72020272/_search
{
"query": {
"bool": {
"must": [
{ "term": { "sold": 0 } },
{ "term": { "isApi": 1 } },
{ "term": { "name.keyword": "myProduct" } }
]
}
}
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/467159.html
標籤:弹性搜索
