miniyao

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

  •  
  •   miniyao · Jun 8, 2018 · 5635 views
    This topic created in 2918 days ago, the information mentioned may be changed or developed.

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

    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 里去)

    No Comments Yet
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   5491 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 36ms · UTC 01:33 · PVG 09:33 · LAX 18:33 · JFK 21:33
    ♥ Do have faith in what you're doing.