【问题标题】:Elasticsearch. filtered query with partial_fields possible?弹性搜索。可以使用 partial_fields 过滤查询吗?
【发布时间】:2014-05-10 18:20:42
【问题描述】:

是否可以从结果中排除某些字段?我正在使用这样的过滤查询:

{
    "size": 10,
    "query": {
        "filtered": {
            "query": {
                "bool": {
                    "should": [
                        {
                            "text": {
                                "name": {
                                    "query": "list",
                                    "operator": "or",
                                    "boost": 30
                                }
                            }
                        },
                        {
                            "text": {
                                "field2": {
                                    "query": "list",
                                    "operator": "or",
                                    "boost": 0.2
                                }
                            }
                        },
                        {
                            "text": {
                                "field1": {
                                    "query": "list",
                                    "operator": "or",
                                    "boost": 0.02
                                }
                            }
                        }
                    ]
                }
            },
            "filter": {
                "and": [
                    {
                        "term": {
                            "_type": "product"
                        }
                    }
                ]
            }
        },
        "filter": {
            "partial_fields": {
                "exclude": "field3"
            }
        }
    },
    "sort": [
        {
            "_score": "desc"
        }
    ]
}

我添加了 filter partial_fields,但它似乎没有任何效果。我正在使用 ES 0.9

【问题讨论】:

    标签: elasticsearch


    【解决方案1】:

    请记住,从 1.0.0beta 开始,partial_fields 支持已被弃用 -

    http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-request-fields.html#partial

    我知道您使用的是 0.9,但在某些时候您需要升级,这种方法将不起作用。我建议升级到 1.x 版本并改用源过滤:

    http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-request-source-filtering.html

    【讨论】:

      【解决方案2】:

      partial_fields 可以根据包含和排除模式返回 _source 的部分表示

      所以我想你应该为排除中的字段名称指定一个通配符模式。如果您的字段名称为 DATA,则排除模式应为 DAT*..

      【讨论】:

      • 是的,我的问题是字段的值应该在 "array" "exclude": ["field3"]
      猜你喜欢
      • 2015-01-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-05-24
      • 2019-12-17
      相关资源
      最近更新 更多