【发布时间】:2015-02-18 07:56:39
【问题描述】:
这里我给出了我更新的映射
curl -X PUT localhost:9200/testing/listings/_mapping -d '{
"listings" : {
"properties" : {
"address" : {
"properties": {
"location": { "type" : "string",
"index" : "not_analyzed"
}
}
},
"suggest" : { "type" : "completion",
"index_analyzer" : "simple",
"search_analyzer" : "simple",
"payloads" : true
}
}
}
}'
我的映射创建索引如下
{
"testing": {
"mappings": {
"listings": {
"properties": {
"address": {
"properties": {
"city": {
"type": "string"
},
"line1": {
"type": "string"
},
"line2": {
"type": "string"
},
"line3": {
"type": "string"
},
"location": {
"type": "string",
"index": "not_analyzed"
},
"pincode": {
"type": "string"
}
}
},
"title": {
"type": "string"
}
}
}
}
}
}
但我的数据仍然不匹配。
我的样本数据是
{
"listings": {
"title": "testing 3",
"address": {
"line1": "3rd cross",
"line2": "6th main",
"line3": "",
"landmark": "",
"location": "k r puram",
"pincode": "",
"city": "Bangalore"
}
}
}
当我以k r puram 给出查询时,我得到了匹配的结果。
但是当我以r r puram 或r k puram 进行查询时,我也得到了属于k r puram 的结果。
在上面的查询中,我只有k r puram 的列表,其他我没有列表,所以除了k r puram 它应该给出空结果。
这是我的查询:
{
"query": {
"bool": {
"must": [
{
"match": {
"published": true
}
},
{
"match": {
"inActive": false
}
},
{
"range": {
"propertyDetailsCategory.build_up_area": {
"lte": 200
}
}
},
{
"match": {
"type": "commercial"
}
},
{
"match": {
"purpose": "rent"
}
},
{
"range": {
"commercialsCategory.exp_rent": {
"lte": 50000
}
}
},
{
"match": {
"address.location": "k r puram"
}
}
]
}
}
}
【问题讨论】:
-
1.为什么只对单个字段使用 multi_match ? 2.“address.location”实际上包含什么? 3、如何分析?
-
我也使用了匹配,那个时候也同样的结果来了。 address.location 包含位置,“address.location”是列表对象中的字段。 @OllyCruickshank
-
让我重新表述我的问题 - “address.location”是否包含“k r puram”的确切值?
-
是的,它包含 k r puram
-
如果数据恰好是“k r puram”并且您正在搜索“k r puram” - 那么听起来您不需要分析仪。您是否在映射中将字段设置为“index”:“not_analyzed”?
标签: node.js mongodb indexing elasticsearch exact-match