是否可以在嵌套字段上使用类似查询的查询? [英] Is it possible to use a more-like-this query on nested fields?
本文介绍了是否可以在嵌套字段上使用类似查询的查询?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个基于(嵌套的)新闻文章的事件"类型,包括标题和文本,它们都具有多字段.
I have an "event" type based on a (nested) press article, including the title, and the text, which both have multifields.
我尝试过:
{
"query":{
"nested":{
"path":"article",
"query":{
"mlt":{
"fields":["article.title.search","article.text.search"],
"max_query_terms": 20,
"min_term_freq": 1,
"include": "false",
"like":[{
"_index":"myindex",
"_type":"event",
"doc":{
"article":{
"title":"this is the title",
"text":"this is the body of the article"
}
}]
}
}
}
}
}
但是它总是返回0次点击
But it always returns 0 hits
推荐答案
{
"query": {
"nested":{
"path":"articles",
"query":{
"more_like_this" : {
"fields" : ["articles.brand", "articles.category", "articles.material"],
"like" : [
{
"_index" : "$index",
"_type" : "$type",
"_id" : "$id"
}
],
"min_term_freq" : 1,
"max_query_terms" : 20
}
}
}
}
这对我有用,考虑到必须将您正在使用的嵌套字段的映射定义为术语向量.
This Works for me, Taking in consideration that the mapping of the nested fields you are using must be defined as term vectors.
"brand": {
"type": "string",
"index": "not_analyzed",
"term_vector": "yes"
}
请参阅: https://www.elastic.co/guide/zh-CN/elasticsearch/reference/current/query-dsl-mlt-query.html
这篇关于是否可以在嵌套字段上使用类似查询的查询?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文