我正在尝试使用elasticsearch completion suggester。我有app_user对象,它们通过couchdb河进入我的弹性搜索实例。
这是我使用的映射:
{
"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
查看生成的文档时,一切似乎都正常:
{
"_index": "myindex",
"_type": "app_user",
"_id": "<someid>",
"found": true,
"_source": {
"_rev": "2-dcd7b9d456e205d3e9d859fdc2c6a688",
"_id": "<someid>",
"email": "joni@example.org",
"suggest": {
"input": [
"joni@example.org",
...
],
"output": "joni surname - joni@example.org",
"payload": {
"_id": "<someid>",
"type": "app_user",
"_rev": "2-dcd7b9d456e205d3e9d859fdc2c6a688",
"label": "joni surname",
"text": "joni@example.org"
}
},
"type": "app_user",
"profile": {
"callname": "",
"fullname": "joni surname"
}
}
}
但是,当我尝试通过_suggest获取文档时,elasticsearch API会以某种方式破坏JSON对象payload
:
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 - joni@example.org","score":1.0,"payload"::)
�_id`<someid>�typeIapp_user�_reva2-dcd7b9d456e205d3e9d859fdc2c6a688�label�joni surname�textSjoni@example.org�}]}]}
绝对没有有效的JSON ..有什么想法吗?