【发布时间】:2016-05-15 10:10:22
【问题描述】:
当我使用 query_string 查询我的索引时,我得到了结果
{
"query": {
"bool": {
"must": [ ],
"must_not": [ ],
"should": [
{
"query_string": {
"default_field": "Printer.Name",
"query": "HL-2230"
}
}
]
}
},
"from": 0,
"size": 10,
"sort": [ ],
"aggs": { }
}
但是当我使用术语查询进行查询时,我没有得到任何结果
{
"query": {
"bool": {
"must": [ ],
"must_not": [ ],
"should": [
{
"term": {
"Printer.Name": "HL-2230"
}
}
]
}
},
"from": 0,
"size": 10,
"sort": [ ],
"aggs": { }
}
我知道 term 是 not_analyzed 并且 query_string 被分析了但是 Name 已经是“HL-2230”,为什么它与 term 查询不匹配?我也尝试使用“hl-2230”搜索,但仍然没有得到任何结果。
编辑:映射如下所示。打印机是产品的孩子。不知道这是否有区别
{
"state": "open",
"settings": {
"index": {
"creation_date": "1453816191454",
"number_of_shards": "5",
"number_of_replicas": "1",
"version": {
"created": "1070199"
},
"uuid": "TfMJ4M0wQDedYSQuBz5BjQ"
}
},
"mappings": {
"Product": {
"properties": {
"index": "not_analyzed",
"store": true,
"type": "string"
},
"ProductName": {
"type": "nested",
"properties": {
"Name": {
"store": true,
"type": "string"
}
}
},
"ProductCode": {
"type": "string"
},
"Number": {
"index": "not_analyzed",
"store": true,
"type": "string"
},
"id": {
"index": "no",
"store": true,
"type": "integer"
},
"ShortDescription": {
"store": true,
"type": "string"
},
"Printer": {
"_routing": {
"required": true
},
"_parent": {
"type": "Product"
},
"properties": {
"properties": {
"RelativeUrl": {
"index": "no",
"store": true,
"type": "string"
}
}
},
"PrinterId": {
"index": "no",
"store": true,
"type": "integer"
},
"Name": {
"store": true,
"type": "string"
}
}
},
"aliases": [ ]
}
}
【问题讨论】:
-
你的
Printer.Name字段的映射是什么? -
@Val 请看我的编辑。我也添加了映射。打印机基本上是 Product 的子级。这可能是问题或区别吗?
标签: elasticsearch