Elasticsearch-dsl-py: [Question] Exclude field from indexing

Created on 23 Oct 2019  路  1Comment  路  Source: elastic/elasticsearch-dsl-py

Hi,

I have the case that I want to exclude a field from indexing (index=false). My object is not really complicated:

class Text(Document):

    value = Text()
    tokens = Nested(Token)  # Token is an InnerDoc

    class Index:
        name = 'documents'

Somehow I have to tell the mapping mechanism that the tokens should not be indexed. I tried to use an Inner Meta class and the mapping attribute to specify this, but without success. I'm pretty sure that this is a minor issue and should be solvable pretty easy. Unfortunately, the documentation is not expressive enough at this point, maybe someone can help out with this.

Most helpful comment

You want to use Object instead and just pass in enabled=False in the constructor:

class Text(Document):

    value = Text()
    tokens = Object(Token, enabled=False, multi=True)  # Token is an InnerDoc

    class Index:
        name = 'documents'

That way the field will be completely ignored by elasticsearch. You don't need to use nested because that only dictates how the index will be created, which we are not doing.

Hope this helps!

>All comments

You want to use Object instead and just pass in enabled=False in the constructor:

class Text(Document):

    value = Text()
    tokens = Object(Token, enabled=False, multi=True)  # Token is an InnerDoc

    class Index:
        name = 'documents'

That way the field will be completely ignored by elasticsearch. You don't need to use nested because that only dictates how the index will be created, which we are not doing.

Hope this helps!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

njoannin picture njoannin  路  3Comments

zahir-koradia picture zahir-koradia  路  3Comments

leoliuxd picture leoliuxd  路  4Comments

SalahAdDin picture SalahAdDin  路  4Comments

barseghyanartur picture barseghyanartur  路  4Comments