[英]ElasticSearch 2.x : more_like_this query and nested objects
我刚刚发现了“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一起使用的答案(除了压平整个索引,我不能这样做。
你们中的任何一个人对这个(奇怪的)问题有什么看法吗? 谢谢 :)
我相信您可以指定要搜索的字段。 您可以尝试直接指向嵌套变量。 像这样的东西
{
"size": 4,
"query": {
"more_like_this": {
"fields": ["id", "title", "description", "categories.id","categories.description", etc...]
"like": [
{
"_index": "client",
"_type": "Presentation",
"_id": "96"
}
],
"min_term_freq": 1,
"max_query_terms": 35,
"min_word_length": 3,
"minimum_should_match": "1%"
}
}
}
我在ES 5.3上有同样的问题(我希望从文档和嵌套文档计算MLT)。
你的bool should
解决方案是非常有帮助的 - 我试图在一个MLT查询内部加入,并且无法弄清楚如何这样做。
通过在嵌套的MLT查询中指定fields
,我能够使这个工作(或者至少看起来工作得很好)。 所以对于你的情况,你会添加:
"fields": ["categories.*"]
到嵌套的MLT查询。 不确定这是否适用于2.x,但认为会提到。
尝试在映射中添加"term_vector": "yes"
属性。
根据文档 ,
必须对要执行MLT的字段建立索引并使用字符串类型。 此外,在文档中使用like时,必须启用_source或必须存储字段或存储term_vector。 为了加速分析,它可以帮助在索引时存储术语向量。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.