当前位置: 动力学知识库 > 问答 > 编程问答 >

json - Elasticsearch type object for a string

问题描述:

Here is a simplified version of my mapping:

{

"mappings": {

"user-event": {

"_all": {

"enabled": true

},

"properties": {

"account_id": {

"type": "string",

"index": "not_analyzed"

},

"name": {

"type": "string"

},

"payload": {

"type": "string",

"index": "not_analyzed"

},

}

},

}

}

Currently payload is a string, and this will be a stringified JSON payload, for instance: "{\"foo\": \"bar\"}"

Is it possible to change the payload type to JSON so that ES automatically parses the string and so I can do query on payload?

If not, do I have to write raw JSON into ES to be able to query it?

网友答案:

ES don't have mapping type JSON, here all available types. But you can change your mapping and use nested type for it, after that you have to re-index all your data and during this re-index you have to post not JSON string but JSON object, something like this:

curl -XPUT localhost:9200/yourIndex/yourType/1 -d '{
    "account_id" : 1,
    "name" : "Admin",
    "payload": {"foo": "bar"}
}'

And everything will work!

分享给朋友:
您可能感兴趣的文章:
随机阅读: