Smile-SA / smile-magento-elasticsearch

Magento ElasticSearch Implementation
151 stars 90 forks source link

Field data loading is forbidden on sku #103

Open jg-development opened 7 years ago

jg-development commented 7 years ago

Hi, I successfully integrated the extension with my magento shop (great extension thx). But I after I added the sku attribute as searchable in the backend all my ajax searches results in errors.

elasticsearch_1  | org.elasticsearch.search.query.QueryPhaseExecutionException: [elasticsearch_20170408-144708][0]: query[filtered(filtered(+function score (+(((autocomplete_de.edge_ngram_front:crystal autocomplete_de.edge_ngram_front:pixi)~2) ((sku:crystal sku:pixi)~2^5.0)), functions: [{filter(QueryWrapperFilter(autocomplete_de.whitespace:crystal autocomplete_de.whitespace:pixi)), function [boost[10.0]]}]))->cache(BooleanFilter(+cache(visibility: visibility:) +cache(status:) +cache(in_stock:T) +cache(store_id:))))->cache(+_type:product +org.elasticsearch.index.search.nested.NonNestedDocsFilter@82d1883f)],from[0],size[3]: Query Failed [Failed to execute main query]
elasticsearch_1  |  at org.elasticsearch.search.query.QueryPhase.execute(QueryPhase.java:163)
elasticsearch_1  |  at org.elasticsearch.search.SearchService.executeFetchPhase(SearchService.java:391)
elasticsearch_1  |  at org.elasticsearch.search.action.SearchServiceTransportAction$11.call(SearchServiceTransportAction.java:333)
elasticsearch_1  |  at org.elasticsearch.search.action.SearchServiceTransportAction$11.call(SearchServiceTransportAction.java:330)
elasticsearch_1  |  at org.elasticsearch.search.action.SearchServiceTransportAction$23.run(SearchServiceTransportAction.java:559)
elasticsearch_1  |  at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
elasticsearch_1  |  at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
elasticsearch_1  |  at java.lang.Thread.run(Thread.java:745)
elasticsearch_1  | Caused by: org.elasticsearch.ElasticsearchException: org.elasticsearch.ElasticsearchIllegalStateException: Field data loading is forbidden on sku
elasticsearch_1  |  at org.elasticsearch.index.fielddata.plain.AbstractIndexFieldData.load(AbstractIndexFieldData.java:80)
elasticsearch_1  |  at org.elasticsearch.search.facet.termsstats.strings.TermsStatsStringFacetExecutor$Collector.setNextReader(TermsStatsStringFacetExecutor.java:134)
elasticsearch_1  |  at org.elasticsearch.common.lucene.MultiCollector.setNextReader(MultiCollector.java:68)
elasticsearch_1  |  at org.apache.lucene.search.IndexSearcher.search(IndexSearcher.java:612)
elasticsearch_1  |  at org.elasticsearch.search.internal.ContextIndexSearcher.search(ContextIndexSearcher.java:191)
elasticsearch_1  |  at org.apache.lucene.search.IndexSearcher.search(IndexSearcher.java:491)
elasticsearch_1  |  at org.apache.lucene.search.IndexSearcher.search(IndexSearcher.java:448)
elasticsearch_1  |  at org.apache.lucene.search.IndexSearcher.search(IndexSearcher.java:281)
elasticsearch_1  |  at org.apache.lucene.search.IndexSearcher.search(IndexSearcher.java:269)
elasticsearch_1  |  at org.elasticsearch.search.query.QueryPhase.execute(QueryPhase.java:157)
elasticsearch_1  |  ... 7 more
elasticsearch_1  | Caused by: org.elasticsearch.common.util.concurrent.UncheckedExecutionException: org.elasticsearch.ElasticsearchIllegalStateException: Field data loading is forbidden on sku
elasticsearch_1  |  at org.elasticsearch.common.cache.LocalCache$Segment.get(LocalCache.java:2203)
elasticsearch_1  |  at org.elasticsearch.common.cache.LocalCache.get(LocalCache.java:3937)
elasticsearch_1  |  at org.elasticsearch.common.cache.LocalCache$LocalManualCache.get(LocalCache.java:4739)
elasticsearch_1  |  at org.elasticsearch.indices.fielddata.cache.IndicesFieldDataCache$IndexFieldCache.load(IndicesFieldDataCache.java:167)
elasticsearch_1  |  at org.elasticsearch.index.fielddata.plain.AbstractIndexFieldData.load(AbstractIndexFieldData.java:74)
elasticsearch_1  |  ... 16 more
elasticsearch_1  | Caused by: org.elasticsearch.ElasticsearchIllegalStateException: Field data loading is forbidden on sku
elasticsearch_1  |  at org.elasticsearch.index.fielddata.plain.DisabledIndexFieldData.fail(DisabledIndexFieldData.java:65)
elasticsearch_1  |  at org.elasticsearch.index.fielddata.plain.DisabledIndexFieldData.loadDirect(DisabledIndexFieldData.java:56)
elasticsearch_1  |  at org.elasticsearch.indices.fielddata.cache.IndicesFieldDataCache$IndexFieldCache$1.call(IndicesFieldDataCache.java:180)
elasticsearch_1  |  at org.elasticsearch.indices.fielddata.cache.IndicesFieldDataCache$IndexFieldCache$1.call(IndicesFieldDataCache.java:167)
elasticsearch_1  |  at org.elasticsearch.common.cache.LocalCache$LocalManualCache$1.load(LocalCache.java:4742)
elasticsearch_1  |  at org.elasticsearch.common.cache.LocalCache$LoadingValueReference.loadFuture(LocalCache.java:3527)
elasticsearch_1  |  at org.elasticsearch.common.cache.LocalCache$Segment.loadSync(LocalCache.java:2319)
elasticsearch_1  |  at org.elasticsearch.common.cache.LocalCache$Segment.lockedGetOrLoad(LocalCache.java:2282)
elasticsearch_1  |  at org.elasticsearch.common.cache.LocalCache$Segment.get(LocalCache.java:2197)
elasticsearch_1  |  ... 20 more

The query from the logs is:

2017-04-08T14:56:48+00:00 DEBUG (7): {"index":"elasticsearch","type":"product","body":{"query":{"filtered":{"query":{"bool":{"must":[{"function_score":{"query":{"bool":{"must":[{"multi_match":{"query":"crystal pixi","type":"best_fields","tie_breaker":1,"fields":["autocomplete_de.edge_ngram_front","sku^5"],"analyzer":"analyzer_de","minimum_should_match":"100%"}}]}},"functions":[{"filter":{"query":{"query_string":{"query":"crystal pixi","default_field":"autocomplete_de.whitespace"}}},"boost_factor":10}]}}]}},"filter":{"bool":{"must":[{"terms":{"visibility":[3,4]}},{"terms":{"status":[1]}},{"terms":{"in_stock":[1]}},{"terms":{"store_id":[1]}}],"_cache":true}}}},"facets":{"sku":{"terms_stats":{"size":"3","order":"total","key_field":"sku","value_script":"_score"}}},"fields":["entity_id"],"track_scores":true,"sort":[{"_score":"desc"}],"from":0,"size":"3"}}

Does anybody have an idea, what the problem is? I use elasticsearch 1.7.6

Greetings Jan

Quazz commented 7 years ago

Afaik, this extension works with elasticsearch 1.5, don't know if 1.7 is supposed to work.

template-provider commented 7 years ago

I will test it with 1.5 and try again

DuckThom commented 7 years ago

I had the same issue, it was not easy to find where the issue was...

We (@elzekool and I) had a long look at the plugin and adding the following code to an observer method listening for the search_engine_product_mapping_properties event made it work (after re-indexing).

    /**
     * Update the mapping for the sku index
     *
     * @param Varien_Event_Observer $event
     * @event search_engine_product_mapping_properties
     * @return void
     */
    public function updateSkuIndexMapping($event)
    {
        /** @var Varien_Object $mapping */
        $mapping = $event->getData('mapping');
        $mappingData = $mapping->getData('properties');

        $mappingData['sku']['index'] = 'not_analyzed';
        $mappingData['sku']['store'] = true;
        $mappingData['sku']['fielddata']['format'] = 'doc_values';

        $mapping->setData('properties', $mappingData);
    }
jg-development commented 7 years ago

thx I will try that and give you feedback