有没有办法排除 Elasticsearch 查询中的字段 [英] Is there a way to exclude a field in an Elasticsearch query

查看:41
本文介绍了有没有办法排除 Elasticsearch 查询中的字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道使用字段设置只包含我想要的字段在搜索中 http://www.elasticsearch.org/guide/reference/api/search/fields/

I know to use the fields setting to include just the fields I want in a search http://www.elasticsearch.org/guide/reference/api/search/fields/

...但我想知道我是否可以做相反的事情...以某种方式指定一两个我不想包含在查询结果中的字段(例如附件).当我可以指定要排除的字段时,必须输入我想要的所有字段减去一两个,这似乎很痛苦

... but I was wondering if I could do the opposite ... somehow specify one or two fields that I don't want included in the query results (like an attachment, for example). It just seems painful to have to type out all the fields I want minus one or two, when I could just specify fields to exclude

推荐答案

您可以使用源过滤(已在 v. 1.6 和 v. 1.7 中测试):https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-source-filtering.html

You can use Source Filtering (Tested in v. 1.6 and v. 1.7): https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-source-filtering.html

{
    "_source": {
        "include": [ "obj1.*", "obj2.*" ],
        "exclude": [ "*.description" ]
    },
    "query" : {
        "term" : { "user" : "kimchy" }
    }
}

您也可以在 GET 请求中使用它:

You can also use it in GET request:

curl "localhost:9200/myindex/mytype/66a8f299870b4cab?_source_exclude=file._content&pretty"

前面的示例排除了附件字段中的文件内容.

The previous example exclude the file content in an attachment field.

这篇关于有没有办法排除 Elasticsearch 查询中的字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆