2013-04-13 23 views
0

当我做这样的查询:如何获得详细的结果输出ElasticSearch

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查询,但我不知道是哪个命令将显示其他信息我在结果之后。

+0

为什么如果你需要禁用_source字段? – dadoonet

+0

嗨dadoonet,我见过的所有文档都没有显示如何包含_source字段。你会提供一个它的使用例子,或者提供一个链接。谢谢。 –

回答

1

正如你已经禁用_source,你要问了明确的领域:

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

documentation

+0

这是完美的。非常感谢你的榜样,我对你负有责任。 –

+0

@AndyBajka只接受dadoonet的回答,你的债务将被视为全额支付;)如果你想启用_source,只需设置''_source“:{”enabled“:true}'而不是'false' – imotov

相关问题