如果doc\u type是类,如何Mapdoc\u type字段

jgovgodb  于 2021-06-15  发布在  ElasticSearch
关注(0)|答案(0)|浏览(116)

我的问题与使用python的ElasticSearch有关,我知道我们可以通过这种方式进行Map

esearch.indices.create(index='test-index', body = request_body,ignore=400)

哪里

request_body =
{"mappings": 
{"TestDocType":
{
"properties":
{
"id":{"type":"integer"}, 
 "name":{"type":"text"}, 
 "description":{"type":"text"}
}
}

}
}

但是我想从这样的类中得到Map

import json
from elasticsearch_dsl import String, Integer, Float, Date, Boolean
from profile_doc import ProfileDocType

class TestDocType(ProfileDocType):

    id = Integer()

    title = String()

    description = String()

    class Meta: 
        index = "Test-index"

    def serialize(self, prod):
        return {
            'id': prod.id,
            'name': prod.title,
            'description': prod.description,
        }

其中profiledoctype是

from datetime import datetime

from elasticsearch_dsl import DocType

    class ProfileDocType(DocType):

        def serialize(self, profile):

            profile["updated_on"] = str(datetime.now())

            return profile

我想得到testdoctype类的Map,并将其添加到索引中如何实现这一点?如果你不明白我的意思,请检查自动Map在c#ElasticSearchhttps://www.elastic.co/guide/en/elasticsearch/client/net-api/current/auto-map.html
非常感谢您的帮助:)

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题