当我这样查询时:

curl 'http://localhost:9200/xenforo/_search?q=message:test'

我得到以下结果:
{
    "took": 3,
    "timed_out": false,
    "_shards": {
        "total": 5,
        "successful": 5,
        "failed": 0
    },
    "hits": {
        "total": 1,
        "max_score": 12.816886,
        "hits": [
            {
                "_index": "xenforo",
                "_type": "post",
                "_id": "1778114",
                "_score": 12.816886
            }
        ]
    }
}

显示了重要的_id,但是我将如何获取更多信息,例如日期,用户和节点信息。

这是我的一些映射信息,我认为重要的部分已显示:
curl -X GET 'http://localhost:9200/xenforo/_mapping?pretty=true'
{
  "xenforo113" : {
    "post" : {
      "_source" : {
        "enabled" : false
      },
      "properties" : {
        "date" : {
          "type" : "long",
          "store" : "yes"
        },
        "discussion_id" : {
          "type" : "long",
          "store" : "yes"
        },
        "message" : {
          "type" : "string"
        },
        "node" : {
          "type" : "long"
        },
        "thread" : {
          "type" : "long"
        },
        "title" : {
          "type" : "string"
        },
        "user" : {
          "type" : "long",
          "store" : "yes"
        }
      }
    },

我假设我将需要进行DSL查询,但是我不知道哪个命令会在结果中显示我想要的其他信息。

最佳答案

禁用_source时,您需要询问显式字段:

curl 'http://localhost:9200/xenforo/_search -d '{
    "fields" : ["user", "date", "node"],
    "query" : {
        "match" : { "message" : "test" }
    }
}'

参见documentation

关于elasticsearch - 如何从ElasticSearch获取详细的结果输出,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/15990665/

10-12 00:18
查看更多