我刚刚发现了“more_like_this”查询类型并尝试将它与我的嵌套对象一起使用。不幸的是,这个查询似乎无法在嵌套对象中搜索。这是我的映射:
"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 只计算“标题”和“描述”字段的分数(而不是查看“类别”)。
{
"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 和嵌套对象属性 ,不幸的是,没有给出可以与 ES 2.x 一起使用的答案(除了展平整个索引,我做不到)。
你们中有人对这个(奇怪的)问题有任何想法吗?谢谢 :)