class PostIndex(DeclarativeIndex): name = "test-post" mappings = { "properties": { "title": Text(), "published_from": Date(), "created_at": Date(), } } document = PostDocument
class User(InnerDocSource): id: int = Long(required=True) signed_up: str = Date() username: str = Text(fields={"keyword": Keyword()}, required=True, multiple=False) email = Text(fields={"keyword": Keyword()}) location = Text(fields={"keyword": Keyword()})
class AutoArchivedPost(DocumentSource): updated = Date(required=True) archived = Boolean() def _post_init_(self) -> None: # automatically archive post that hasn't been updated in a while if self.updated and self.updated < "2020": self.archived = True
class AutoDatePost(DocumentSource): author = Object(properties=User, required=True) updated = Date(required=True) body = Text(required=True) comments = Nested(properties=Comment, multiple=True) def _pre_save_op_(self): if self.updated is None: # TODO - handle datetime serialization self.updated = "2021-01-01"
class PostTemplate(DeclarativeIndexTemplate): name = "test-template" index_patterns = "test-post*" template = { "mappings": { "properties": { "title": Text(), "published_from": Date() } }, "settings": { "number_of_shards": 1 }, "aliases": { "post": {} }, }
class Post(DocumentSource): author = Object(properties=User, required=True) created = Date(required=True) body = Text(required=True) comments = Nested(properties=Comment, multiple=True)
class Comment(InnerDocSource): author = Object(properties=User, required=True) created = Date(required=True) content = Text(required=True)
class PostDocument(DocumentSource): title = Text() published_from = Date()
class Post(DeclarativeIndex): name = "test-post" mappings = {"properties": {"title": Text(), "published_from": Date()}} settings = {"number_of_shards": 1} aliases = {"post": {}}