V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
miniyao
V2EX  ›  Elasticsearch

ES 添加索引 index 数据时,要过滤 filter 部分数据不被索引,该怎么定义数据模型呢?

  •  
  •   miniyao · 2018-06-08 10:13:45 +08:00 · 2592 次点击
    这是一个创建于 2362 天前的主题,其中的信息可能已经有所发展或是发生改变。

    翻了下光头哥的博客介绍:

    The first thing that I need, is to somehow find a generic way to indicate which model and which field or fields in it are to be indexed. I'm going to say that any model that needs indexing needs to define a searchable class attribute that lists the fields that need to be included in the index. For the Post model, these are the changes:

    app/models.py: Add a __searchable__ attribute to the Post model.

    class Post(db.Model):
        __searchable__ = ['body']
        # ...
    

    例如 Post 数据类里增加 status = private (or public) 这个 filter:

    class Post(db.Model):
        __searchable__ = ['body']
        status = private (or public)
        # ...
    

    然后往 Elasticsearch 增加索引数据时,只选择 status = public 类型的 post.body,该怎么定义这个数据模型呢? (意思是不能把 private 的数据添加到在 ES 里去)

    目前尚无回复
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   5625 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 29ms · UTC 07:10 · PVG 15:10 · LAX 23:10 · JFK 02:10
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.