【发布时间】:2015-03-03 11:13:59
【问题描述】:
我有这个映射:
"post": {
"model": "Post",
"properties": {
"id": {
"type": "integer"
},
"title": {
"type": "string",
"analyzer": "custom_analyzer",
"boost": 5
},
"description": {
"type": "string",
"analyzer": "custom_analyzer",
"boost": 4
},
"condition": {
"type": "integer",
"index": "not_analyzed"
},
"categories": {
"type": "string",
"index": "not_analyzed"
},
"seller": {
"type": "nested",
"properties": {
"id": {
"type": "integer",
"index": "not_analyzed"
},
"username": {
"type": "string",
"analyzer": "custom_analyzer",
"boost": 1
},
"firstName": {
"type": "string",
"analyzer": "custom_analyzer",
"boost": 3
},
"lastName": {
"type": "string",
"analyzer": "custom_analyzer",
"boost": 2
}
}
},
"marketPrice": {
"type": "float",
"index": "not_analyzed"
},
"currentPrice": {
"type": "float",
"index": "not_analyzed"
},
"discount": {
"type": "float",
"index": "not_analyzed"
},
"commentsCount": {
"type": "integer",
"index": "not_analyzed"
},
"likesCount": {
"type": "integer",
"index": "not_analyzed"
},
"featured": {
"type": "boolean",
"index": "not_analyzed"
},
"bumped": {
"type": "boolean",
"index": "not_analyzed"
},
"created": {
"type": "date",
"index": "not_analyzed"
},
"modified": {
"type": "date",
"index": "not_analyzed"
}
}
}
这个查询:
GET /develop/_search?search_type=dfs_query_then_fetch
{
"query": {
"filtered" : {
"query": {
"bool": {
"must": [
{ "match": { "title": "post" }}
]
}
},
"filter": {
"bool": {
"must": [
{"term": {
"featured": 0
}},
{
"nested": {
"path": "seller",
"filter": {
"bool": {
"must": [
{ "term": { "seller.firstName": "Test 3" } }
]
}
},
"_cache" : true
}}
]
}
}
}
},
"sort": [
{
"_score":{
"order": "desc"
}
},{
"created": {
"order": "desc"
}
}
],
"track_scores": true
}
我等待 25 个结果,因为我有 25 个帖子被索引。但我得到一个空集。如果我删除嵌套过滤器一切正常。我希望能够过滤嵌套对象
编辑:
在我的设置中:
"analyzer": {
"custom_analyzer": {
"type": "custom",
"tokenizer": "nGram",
"filter": [
"stopwords",
"asciifolding",
"lowercase",
"snowball",
"english_stemmer",
"english_possessive_stemmer",
"worddelimiter"
]
},
"custom_search_analyzer": {
"type": "custom",
"tokenizer": "standard",
"filter": [
"stopwords",
"asciifolding",
"lowercase",
"snowball",
"english_stemmer",
"english_possessive_stemmer",
"worddelimiter"
]
}
}
我在这里缺少什么。
谢谢
【问题讨论】:
-
您能发布您对
custom_analyzer的定义吗?它的设置方式可能与您的问题有关。 -
嘿@SloanAhrens 我用我的分析器更新问题
-
我仍然无法建立一个像你这样的索引来测试它。看起来您也定义了一些自定义过滤器?你也可以发这些吗?一些示例文档也可能会有所帮助。如果无法模拟您的系统,很难告诉您问题出在哪里。
-
我的怀疑是,在您当前的设置下,
{ "term": { "seller.firstName": "Test 3" } }必须是{ "term": { "seller.firstName": "test" } },或类似的东西。或者您将需要调整您的分析器/映射。但是如果不直接测试就很难确定。 -
@SloanAhrens 关于这个问题stackoverflow.com/questions/27493452/… 我发布了相同的数据和映射,但出于不同的原因,它是相同的
标签: search filter elasticsearch nested