elastic / elasticsearch-dsl-py

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

missing custom class #264

Closed nahuelange closed 8 years ago

nahuelange commented 8 years ago

Trying to make my own analyzer I got this error : The type is set to custom, but can't be instanciated… because it's missing. I made something wrong?

/home/workspace/eggs/elasticsearch_dsl-0.0.8-py2.7.egg/elasticsearch_dsl/analysis.pyc in _type_shortcut(cls, name_or_instance, type, **kwargs)
    109         if type is None:
    110             type = 'custom'
--> 111         return cls.get_dsl_class(type)(name_or_instance, **kwargs)
    112 
    113 class Analyzer(AnalysisBase, DslBase):

/home/workspace/eggs/elasticsearch_dsl-0.0.8-py2.7.egg/elasticsearch_dsl/utils.pyc in get_dsl_class(cls, name)
    194             return cls._classes[name]
    195         except KeyError:
--> 196             raise UnknownDslObject('DSL class `%s` does not exist in %s.' % (name, cls._type_name))
    197 
    198     def __init__(self, **params):

UnknownDslObject: DSL class `custom` does not exist in token_filter.
honzakral commented 8 years ago

I am sorry, if you don't post the code that's causing your issues there is nothing I can do. Could you please post the code and a description of what the code/analyzer is supposed to do? Thanks

honzakral commented 8 years ago

With no code I cannot tell what's going on. Feel free to reopen the issue if you can replicate it. Thanks!

dbateman commented 8 years ago

I may have run into the same issue, although having just started using elasticsearch-dsl it could be my n00bieness that's the cause! Say I want to create a custom analyzer that uses an autocomplete_filter of type edgeNGram, as defined below:

from elasticsearch_dsl.analysis import CustomAnalyzer, EdgeNGramTokenFilter

autocomplete_filter = EdgeNGramTokenFilter(
    'autocomplete_filter',
    min_gram=1,
    max_gram=20
)

autocomplete = CustomAnalyzer(
    'autocomplete',
    tokenizer='standard',
    filter=['lowercase', 'autocomplete_filter']
)

When I try to build the mapping, I get the following exception:

File "/some/local/path/python2.7/site-packages/elasticsearch_dsl/utils.py", line 196, in get_dsl_class
    raise UnknownDslObject('DSL class `%s` does not exist in %s.' % (name, cls._type_name))
elasticsearch_dsl.exceptions.UnknownDslObject: DSL class `custom` does not exist in token_filter.

I suspect this is what the OP was also trying to do...

honzakral commented 8 years ago

Thanks! This error is definitely misleading and should be fixed. What is going on, however, is that you are not passing in the filter but just it's name. There is then no way for the analyzer (autocomplete) to know where to take the autocomplete_filter you refer to. Correct way is to pass the token filter itself, not its name.

dbateman commented 8 years ago

Ah! Of course. Thanks for the lightning response.

thavidu commented 8 years ago

Hi, I have a similar issue. I'm trying to use the following custom analyzer:

html_kuromoji = analyzer('html_kuromoji',
    tokenizer='kuromoji_tokenizer',
    filter=['kuromoji_baseform','kuromoji_part_of_speech','cjk_width','ja_stop','kuromoji_stemmer', 'lowercase'],
    char_filter=['html_strip']
)

but I'm getting the error:

elasticsearch_dsl.exceptions.UnknownDslObject: DSL classcustomdoes not exist in token_filter.

Note, these "kuromoji_" things are from the official elasticsearch japanese plugin, which I installed on the server via: bin/plugin -install elasticsearch/elasticsearch-analysis-kuromoji/2.7.0

I test a simple analyze call using curl and it seems the analyzer is installed.

Am I declaring this custom analyzer wrong?

honzakral commented 8 years ago

I am sorry @thavidu, I completely missed your question here. Please see #328 which is exactly the same issue.