2017-04-06 111 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