2014-12-13 91 views
0

我正在嘗試使用elasticsearch completion suggester。我有app_user對象,它通過couchdb河進入我的elasticsearch實例。Elasticsearch - 完成建議有效負載轉換,返回無效的JSON

這是我使用的映射:

{ 
    "app_user" : { 
     "_all" : {"enabled" : true}, 
     "_source" : { 
      "includes" : [ 
       "_id", 
       "_rev", 
       "type", 
       "profile.callname", 
       "profile.fullname", 
       "email" 
      ] 
     }, 
     "properties" : { 
      "suggest" : { "type" : "completion", 
          "index_analyzer" : "simple", 
          "search_analyzer" : "simple", 
          "payloads" : true 
      } 
     }, 
     "transform" : [ 
      {"script": "ctx._source.suggest = ['input':[ctx._source.email, ctx._source.profile.fullname, ctx._source.profile.callname]]"}, 
      {"script": "ctx._source.suggest.payload = ['_id': ctx._source['_id'], 'type': ctx._source['type'], '_rev': ctx._source['_rev']]"} 
      , 
      {"script": "ctx._source.suggest.payload << ['label': ctx._source.profile.fullname, 'text': ctx._source.email]"} 
     ] 
    } 
} 

所以我想包括對象ID,並在有效載荷的顯示文本。 當我通過http://localhost:9200/myindex/app_user/<someid>?pretty&_source_transform查看生成的文檔,似乎一切都OK:

{ 
    "_index": "myindex", 
    "_type": "app_user", 
    "_id": "<someid>", 
    "found": true, 
    "_source": { 
     "_rev": "2-dcd7b9d456e205d3e9d859fdc2c6a688", 
     "_id": "<someid>", 
     "email": "[email protected]", 
     "suggest": { 
      "input": [ 
       "[email protected]", 
       ... 
      ], 
      "output": "joni surname - [email protected]", 
      "payload": { 
       "_id": "<someid>", 
       "type": "app_user", 
       "_rev": "2-dcd7b9d456e205d3e9d859fdc2c6a688", 
       "label": "joni surname", 
       "text": "[email protected]" 
      } 
     }, 
     "type": "app_user", 
     "profile": { 
      "callname": "", 
      "fullname": "joni surname" 
     } 
    } 
} 

但是,當我試圖讓通過_suggest文檔,elasticsearch API在某種程度上打破了JSON對象​​:

curl -XGET "http://localhost:9200/myindex/_suggest" -d '{ 
    "all-suggest": { 
     "text": "joni", 
     "completion": { 
      "field": "suggest" 
     } 
    } 
}' 

結果在

{"_shards":{"total":5,"successful":5,"failed":0},"all-suggest":[{"text":"joni","offset":0,"length":5,"options":[{"text":"joni surname - [email protected]","score":1.0,"payload"::) 
�_id`<someid>�typeIapp_user�_reva2-dcd7b9d456e205d3e9d859fdc2c6a688�label�joni surname�[email protected]�}]}]} 

這是絕對沒有有效的JSON ..任何想法?

回答

0

這實際上是elasticsearch中的一個錯誤。據報道並承認here,應該是fixed shortly

+0

現在修復:https://github.com/elastic/elasticsearch/commit/a95d75e074488b431e014729e17d719798e62c29 – joni 2015-04-16 12:58:56