elasticsearch - elasticsearch:在has_parent查询中增强文档

标签 elasticsearch

有没有办法增强从has_parent查询“出现”的文档?

{
  "query": {
      "function_score": {
          "query": {
              "bool": {
                  "should": [
                      {
                          "multi_match": {
                              "fields": ["name^3", "tags^2", "content"],
                              "query": "xx"
                          }
                      },
                      {
                          "has_parent": {
                              "type": "theparent",
                              "query": {
                                  "multi_match": {
                                      "type": "best_fields",
                                      "fields": ["name^5", "content"],
                                      "query": "xx"
                                  }
                              }
                          }
                      },
                      {
                          "has_child": {
                              "type": "thechild",
                              "query": {
                                  "multi_match": {
                                      "fields": ["name^3","content"],
                                      "query": "xx"
                                  }
                              }
                          }
                      }
                  ]
              }
          },
          "score_mode": "sum",
          "functions": [
              {
                  "linear": {
                      "date": {
                          "origin": "2014-08-29",
                          "scale": "700d",
                          "decay": 0.6
                      }
                  }
              }
          ]
      }
  }

更确切地说,我只想在查询与父项的名称字段匹配时提升这些文档
(我还没有找到一种方法来引用functions中的父字段,即theparent._source.name ~= "xx")

最佳答案

根据sources from Github (see line 104)boost查询中允许使用has_parent参数。

基于此属性,可以专门增强包含should查询的has_parent子句。在您的情况下,结果将是:

...
                  {
                      "has_parent": {
                          "type": "theparent",
                          "query": {
                              "multi_match": {
                                  "type": "best_fields",
                                  "fields": ["name^5", "content"],
                                  "query": "xx"
                              }
                          },
                          "boost": 5
                      }
                  }
...

我不知道它是否可以为您提供帮助,但是您会发现有关增强查询子句here的更多见解。

关于elasticsearch - elasticsearch:在has_parent查询中增强文档,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25573103/

相关文章:

node.js - 具有过滤器和聚合的 Elastic Search 查询不返回聚合

elasticsearch - 跨多个字段的multi_match模糊查询

elasticsearch - 在Elasticsearch中查询数组中的部分匹配

elasticsearch - 在基本的hello world应用程序中使用Nest的 Elasticsearch 结果不一致

elasticsearch - Elasticsearch-从结构中删除字段

elasticsearch - 是否可以进行祖 parent 子女查询

elasticsearch - CURL:不支持Content-Type header [application/x-www-form-urlencoded]

ElasticSearch multi_match 如果字段存在则应用过滤器否则不用担心?

elasticsearch - Elasticsearch查询聚合

elasticsearch - && 和 || 怎么做在 NEST 中构建查询?