2017-04-06 73 views
0

我发送以下弹性搜索查询,它通过uri-search发送时表现非常好。但随着身体呼叫的帖子 - 它没有按预期工作。请建议如何更正查询。ElasticSearch:查询文章正文不工作,但uri搜索工作

这工作:

GET CALL

<someUrl>/elasticsearch/index/_search?q=host:host-0 

RESPONSE(仅限于主机-0)

{ 
    "took": 4, 
    "timed_out": false, 
    "_shards": { 
     "total": 5, 
     "successful": 5, 
     "failed": 0 
    }, 
    "hits": { 
     "total": 128040, 
     "max_score": 2.0973763, 
     "hits": [{ 
       "_index": "123" 
       "_type": "log_message", 
       "_id": "123", 
       "_score": 111, 
       "_source": { 
        "host": "host-0", 
        "pid": 333, 
        "timestamp": "2017-04-06T04:29:44.724Z", 
        "priority": 7, 
        "namespace": "syslog", 
        "msg": "aaaaa" 
       } 
      }, 

      "_index": "345" 
      "_type": "log_message", 
      "_id": "345", 
      "_score": 111, 
      "_source": { 
       "host": "host-0", 
       "pid": 333, 
       "timestamp": "2017-04-06T04:29:44.724Z", 
       "priority": 7, 
       "namespace": "syslog", 
       "msg": "aaaaa" 
      } 
     }, 
     ..... 
} 

这不起作用:

POST CALL

<someUrl>/elasticsearch/index/_search 

机构POST电话:

{ 
    "query" : { 
     "term" : { "host": "host-0" } 
    } 
} 

RESPONSE(不限制托管-0)

{ 
    "took": 4, 
    "timed_out": false, 
    "_shards": { 
     "total": 5, 
     "successful": 5, 
     "failed": 0 
    }, 
    "hits": { 
     "total": 128040, 
     "max_score": 2.0973763, 
     "hits": [{ 
       "_index": "123" 
       "_type": "log_message", 
       "_id": "123", 
       "_score": 111, 
       "_source": { 
        "host": "host-1", 
        "pid": 333, 
        "timestamp": "2017-04-06T04:29:44.724Z", 
        "priority": 7, 
        "namespace": "syslog", 
        "msg": "aaaaa" 
       } 
      }, 

      "_index": "345" 
      "_type": "log_message", 
      "_id": "345", 
      "_score": 111, 
      "_source": { 
       "host": "host-0", 
       "pid": 333, 
       "priority": 7, 
       "namespace": "syslog", 
       "msg": "aaaaa" 
      } 
     }, 
      "_index": "546" 
      "_type": "log_message", 
      "_id": "546", 
      "_score": 111, 
      "_source": { 
       "host": "host-0", 
       "pid": 222,     
       "priority": 7, 
       "namespace": "syslog", 
       "msg": "aaaaa" 
      } 
     }, 
     ..... 
} 

该指标的获取返回 GET/elasticsearch/

 "host": { 
     "type": "string", 
     "index": "not_analyzed" 
     }, 
+0

您如何发送您的查询?用哪个客户? – Val

+0

也请分享您的架构映射和版本 – user3775217

+0

我是elasticsearch的新手 - 我如何检索版本和映射? – BabyGroot

回答

1

在您的GET调用中,分析令牌host-0。如果你尝试下面的GET调用(用双引号围绕host-0),你将获得与POST调用相同的查询,并且你不会得到任何结果。

<someUrl>/elasticsearch/index/_search?q=host:"host-0" 

如果你想要的结果,你需要使用一个match查询,而不是一个term之一。这将相当于GET调用中的...?q=host:host-0

{ 
    "query" : { 
     "match" : { "host": "host-0" } 
    } 
} 

最后,我认为你host场有text类型,而它应有的keyword类型。

+0

OP说他正在为GET和POST调用获得结果(在这种情况下,这对我来说看起来很奇怪)。如果分析了host字段,那么除非他使用其他分析器,否则我们不应该得到POST调用的结果! – avr

+0

这是我得到越来越指数 “主机”:{ “类型”:“串”, “指数”:“not_analyzed” }, – BabyGroot

+0

这似乎更邮递员工具的问题 - 从命令行结果卷曲工作正常 – BabyGroot