【问题标题】:How to search for indices which does not have a specific field in Elasticsearch如何在 Elasticsearch 中搜索没有特定字段的索引
【发布时间】:2017-12-24 05:56:55
【问题描述】:

我有一个具有 1000 多个索引的弹性搜索集群,我的大多数索引都具有纪元格式的特定时间戳,但是很少有索引具有 UTC 时间戳,当有人试图从 kibana 搜索时,这会导致查询崩溃,我正在尝试列出所有没有名为 ts 的文件的索引,我可以通过 curl 获取字段映射 culr -XGET http://es-node1:9200/*/_mapping/field/ts?pretty

但是遍历所有 1000 多个结果非常乏味,有人可以指点我正确的查询以排除所有没有字段“ts”的索引

如果我从集群中的 kibana 节点运行查询开始对 cpu 进行峰值处理,那么我正在运行的过滤器是

"filter": {
  "list": {
    "0": {
      "type": "time",
      "field": "ts",
      "from": "now-5m",
      "to": "now",
      "mandate": "must",
      "active": true,
      "alias": "",
      "id": 0
    },
    "1": {
      "type": "querystring",
      "query": "_exists_:ts",
      "mandate": "must",
      "active": true,
      "alias": "",
      "id": 1
    }
  },
  "ids": [
    0,
    1
  ],
  "hide": true
}

},

这是我在我的 ES 节点中得到的日志。

[2017-07-19 06:35:12,874][DEBUG][action.search            ] [Gargoyle] [ws][4], node[FbXhw2ERQT6QDPmNCuOMGQ], [R], v[21], s[STARTED], a[id=iH_6483qRHmJGSk95rOtQg]: Failed to execute [org.elasticsearch.action.search.SearchRequest@4078c587] lastShard [true]

RemoteTransportException[[Captain America][es-node1:9300][indices:data/read/search[phase/query]]];嵌套:SearchParseException [未能解析搜索源 [{“query”:{“filtered”:{“query”:{“bool”:{“should”:[{“query_string”:{“query”:“ "}}]}},"filter":{"bool":{"must":[{"range":{"ts":{"from":1500445811001,"to":1500446111001}}},{" fquery":{"query":{"query_string":{"query":"ts:(1500446010000)"}},"_cache":true}}]}}}},"highlight":{"fields": {},"fragment_size":2147483647,"pre_tags":["@start-highlight@"],"post_tags":["@end-highlight@"]},"size":1000,"sort":[{ "_score":{"order":"desc"}},{"ts":{"order":"desc"}}]}]];嵌套:SearchParseException [未找到 [ts] 的映射以便排序]; 原因:SearchParseException[解析搜索源失败[{"query":{"filtered":{"query":{"bool":{"should":[{"query_string":{"query":" em>"}}]}},"filter":{"bool":{"must":[{"range":{"ts":{"from":1500445811001,"to":1500446111001}}}, {"fquery":{"query":{"query_string":{"query":"ts:(1500446010000)"}},"_cache":true}}]}}}},"highlight":{"字段":{},"fragment_size":2147483647,"pre_tags":["@start-highlight@"],"post_tags":["@end-highlight@"]},"size":1000,"sort": [{"_score":{"order":"desc"}},{"ts":{"order":"desc"}}]}]];嵌套:SearchParseException [未找到 [ts] 的映射以便排序]; 在 org.elasticsearch.search.SearchService.parseSource(SearchService.java:855) 在 org.elasticsearch.search.SearchService.createContext(SearchService.java:654) 在 org.elasticsearch.search.SearchService.createAndPutContext(SearchService.java:620) 在 org.elasticsearch.search.SearchService.executeQueryPhase(SearchService.java:371) 在 org.elasticsearch.search.action.SearchServiceTransportAction$SearchQueryTransportHandler.messageReceived(SearchServiceTransportAction.java:368) 在 org.elasticsearch.search.action.SearchServiceTransportAction$SearchQueryTransportHandler.messageReceived(SearchServiceTransportAction.java:365) 在 org.elasticsearch.transport.TransportRequestHandler.messageReceived(TransportRequestHandler.java:33) 在 org.elasticsearch.transport.RequestHandlerRegistry.processMessageReceived(RequestHandlerRegistry.java:75) 在 org.elasticsearch.transport.netty.MessageChannelHandler$RequestHandler.doRun(MessageChannelHandler.java:300) 在 org.elasticsearch.common.util.concurrent.AbstractRunnable.run(AbstractRunnable.java:37) 在 java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) 在 java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) 在 java.lang.Thread.run(Thread.java:745) 原因:SearchParseException [未找到 [ts] 的映射以便排序] 在 org.elasticsearch.search.sort.SortParseElement.addSortField(SortParseElement.java:212) 在 org.elasticsearch.search.sort.SortParseElement.addCompoundSortField(SortParseElement.java:186) 在 org.elasticsearch.search.sort.SortParseElement.parse(SortParseElement.java:84) 在 org.elasticsearch.search.SearchService.parseSource(SearchService.java:838) ... 12 更多

我正在尝试删除其中没有字段“ts”的索引,因为我正在寻找一个查询,我只能获取没有字段 ts 的索引,有人可以帮我吗与查询?

【问题讨论】:

    标签: elasticsearch kibana


    【解决方案1】:

    在 Kibana 中,您可以使用 _exists_ query 并将以下内容添加到您的查询中

    _exists_:ts AND ...the rest of your query
    

    【讨论】:

    • Val,谢谢您的回复,当我使用 exists 进行查询时:ts 仍然提供 SearchParseException 嵌套:SearchParseException[No mapping found for [ts] 以便排序];
    • 您能否打开请求选项卡并使用发送到 ES 的完整查询更新您的问题?
    • 确保更新查询
    猜你喜欢
    • 2018-08-01
    • 1970-01-01
    • 2018-08-18
    • 1970-01-01
    • 2016-09-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多