elastic / elasticsearch-dsl-py

High level Python client for Elasticsearch
http://elasticsearch-dsl.readthedocs.org
Apache License 2.0
3.82k stars 801 forks source link

got an unexpected keyword argument 'data_only' #936

Closed foolcage closed 6 years ago

foolcage commented 6 years ago

I use elasticsearch-dsl == 6.2.1

{
  "name" : "67G84Xb",
  "cluster_name" : "elasticsearch",
  "cluster_uuid" : "C4Q4oVYHTIyTWtpUyUP_lA",
  "version" : {
    "number" : "6.2.4",
    "build_hash" : "ccec39f",
    "build_date" : "2018-04-12T20:37:28.497551Z",
    "build_snapshot" : false,
    "lucene_version" : "7.2.1",
    "minimum_wire_compatibility_version" : "5.6.0",
    "minimum_index_compatibility_version" : "5.0.0"
  },
  "tagline" : "You Know, for Search"
}

Got error:

  File "/elasticsearch_dsl/field.py", line 163, in _wrap
    return self._doc_class.from_es(data, data_only=True)
TypeError: from_es() got an unexpected keyword argument 'data_only'
honzakral commented 6 years ago

Thank you, could you please share the definition of the document class that causes this exception?

foolcage commented 6 years ago

here is the document:

class PriceCondition(BaseDocType):
    securityType = Keyword()
    exchange = Keyword()
    code = Keyword()
    upPct = Float()
    downPct = Float()
    upTo = Float()
    downTo = Float()

class PriceSubscription(BaseDocType):
    """
    {
        "id": 123,
        "userId": 111,
        "type": "price",
        "condition": {
            "securityType": "cryptocurrency",
            "exchange": "binance",
            "code": "BTC-USDT",
            "upPct": 1,
            "downPct": 2,
            "up": 7000,
            "down": 6000
        },
        "actions": [weixin,email,shortMsg],
        "repeat": False
    }
    """
    id = Keyword()
    userId = Keyword()
    condition = Nested(PriceCondition)
    repeat = Boolean()
    actions = Keyword()

    class Meta:
        doc_type = 'doc'
        all = MetaField(enabled=False)

https://github.com/foolcage/fooltrader/blob/bot/fooltrader/domain/subscription_model.py

I try elasticsearch-dsl == 6.2.1 and it cause the error,so I switched to 6.1.0 now.

honzakral commented 6 years ago

Problem is that PriceCondition cannot extend DocType but must be extending InnerDoc.I will make a note to fix it so that it won't break but for now just change its base from BaseDocType to InnerDoc and it should help.

asrenzo commented 5 years ago

Hi, Imagine you want PriceCondition to be a real Document (for example for some Kibana graphs) but you also wan't to add a PriceCondition within a PriceSubscription Document. How should we do this ?

Regards,

littlehome-eugene commented 5 years ago

I'm having similar issue, with

elasticsearch==6.3.1 elasticsearch-dsl==6.3.1

 class ReviewMeta(InnerDoc):

     id = Integer()
     name = Keyword()
     tags = Keyword()
     location = GeoPoint()
     area_names = Keyword()

 class ReviewMetaSearchClickLogDoc(DocType):

     id = Integer()
     created_at = Date()
     search_log_id = Integer()
     review_meta = Object(ReviewMeta)
     position = Integer()

     class Index:
         name = REVIEWMETA_SEARCH_CLICK_LOG_INDEX

 class ReviewMetaSearchLogDoc(DocType):

     id = Integer()
     created_at = Date()
     user = Object(User)
     result_count = Integer()
     search_data = Object(dynamic=True)
     clicks = Nested(ReviewMetaSearchClickLogDoc, include_in_parent=True)

     class Index:
         name = REVIEWMETA_SEARCH_LOG_INDEX

I guess the problem is Nested(ReviewMetaSearchClickLogDoc, include_in_parent=True) , why is it a problametic, and how can I fix it?