【发布时间】:2016-10-10 09:25:54
【问题描述】:
我刚刚发现了"more_like_this" query type 并尝试将它与我的嵌套对象一起使用。 不幸的是,这个查询似乎无法在嵌套对象中搜索。这是我的地图:
"Presentation": {
"properties": {
"id": {
"include_in_all": false,
"type": "string"
},
"title": {
"include_in_all": true,
"type": "string"
},
"description": {
"include_in_all": true,
"type": "string"
},
"categories": {
"properties": {
"id": {
"include_in_all": false,
"type": "string"
},
"category": {
"include_in_all": true,
"type": "string"
},
"category_suggest": {
"properties": {
"input": {
"type": "string"
},
"payload": {
"properties": {
"id": {
"type": "long"
}
}
}
}
}
},
"type": "nested"
}
}
}
我的目标是找到所有与 id "96" 相关的演示文稿,并提升与 "96" 具有相同类别的演示文稿。 但是,在执行下面的查询时,Elasticsearch 只计算“title”和“description”字段的分数(而不是查看“category”)。
{
"size": 4,
"query": {
"more_like_this": {
"like": [
{
"_index": "client",
"_type": "Presentation",
"_id": "96"
}
],
"min_term_freq": 1,
"max_query_terms": 35,
"min_word_length": 3,
"minimum_should_match": "1%"
}
}
}
我也尝试在嵌套字段上强制查询,但它也不起作用:
{
"size": 4,
"query": {
"bool": {
"should": [
{
"more_like_this": {
"like": [
{
"_index": "client",
"_type": "Presentation",
"_id": "96"
}
],
"min_term_freq": 1,
"max_query_terms": 35,
"min_word_length": 3,
"minimum_should_match": "1%"
}
},
{
"nested" : {
"path":"categories",
"query" : {
"more_like_this": {
"like": [
{
"_index": "client",
"_type": "Presentation",
"_id": "96"
}
],
"min_term_freq": 1,
"max_query_terms": 35,
"min_word_length": 3,
"minimum_should_match": "1%"
}
}
}
}
]
}
}
}
我发现这个人也有同样的问题,但使用的是旧版本的 elasticsearch:ElasticSearch More_Like_This API and Nested Object Properties 而且,不幸的是,没有给出可以与 ES 2.x 一起使用的答案(除了展平整个索引,这是我做不到的)。
你们中有人对这个(奇怪的)问题有任何想法吗? 谢谢:)
【问题讨论】:
标签: elasticsearch elasticsearch-2.0