Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

QueryBuilders and FilterBuilders have dependency on spatial4j which is optional. #2519

Closed
yurkom opened this issue Jan 3, 2013 · 7 comments

Comments

@yurkom
Copy link

yurkom commented Jan 3, 2013

IMHO, these classes shouldn't have hard dependencies on spatial4j library which is optional.
There is two way to resolve this issue:

  • Make the dependency on spatial4j required (optional=false)
  • or move geoShape* to the separate GeoQueryBuilders and GeoFilterBuilders factory classes

The latest solution allows to keep the library optional. And it allows to use it when it is really necessary.

As one more solution, it is move geo-shape functionality to the separate library like a plugin.

@kimchy
Copy link
Member

kimchy commented Jan 6, 2013

Do you get a failure in this case? I tested it, and it works fine even if you don't have the spatial4j lib in the classpath, assuming you don't call the builders that require it.

@yurkom
Copy link
Author

yurkom commented Jan 8, 2013

I have found that it is not an issue for Java. It is reproduced in the Scala compiler (ver. 2.9.2). I tested two simple classes for Java and Scala. They did the same work. And the scala code got a failure.

import org.elasticsearch.index.query.FilterBuilders._

class ElasticTest {
  def test {
    orFilter(termFilter("key", "phrase"))
  }
}
error: error while loading FilterBuilders, Missing dependency 'class com.spatial4j.core.shape.Shape', required by c:\lib\elastic.jar(org/elasticsearch/index/query/FilterBuilders.class)
ElasticTest.scala:5: error: not found: value orFilter
    orFilter(termFilter("key", "phrase"))
    ^
two errors found

About the issue:
https://issues.scala-lang.org/browse/SI-5343
http://www.scala-lang.org/node/12342

@yurkom yurkom closed this as completed Jan 8, 2013
@danklynn
Copy link

This issue is also present in the Groovy runtime:

// this throws a NoClassDefFoundError:
def query = QueryBuilders.boolQuery()

java.lang.NoClassDefFoundError: com/spatial4j/core/shape/Shape
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Class.java:2427)
at java.lang.Class.getDeclaredMethods(Class.java:1791)
at org.codehaus.groovy.reflection.CachedClass$3$1.run(CachedClass.java:84)
at java.security.AccessController.doPrivileged(Native Method)
at org.codehaus.groovy.reflection.CachedClass$3.initValue(CachedClass.java:81)
at org.codehaus.groovy.reflection.CachedClass$3.initValue(CachedClass.java:79)
at org.codehaus.groovy.util.LazyReference.getLocked(LazyReference.java:46)
at org.codehaus.groovy.util.LazyReference.get(LazyReference.java:33)
at org.codehaus.groovy.reflection.CachedClass.getMethods(CachedClass.java:250)
at groovy.lang.MetaClassImpl.populateMethods(MetaClassImpl.java:305)
at groovy.lang.MetaClassImpl.fillMethodIndex(MetaClassImpl.java:284)
at groovy.lang.MetaClassImpl.initialize(MetaClassImpl.java:2904)
at groovy.lang.ExpandoMetaClass.initialize(ExpandoMetaClass.java:483)
at org.codehaus.groovy.reflection.ClassInfo.getMetaClassUnderLock(ClassInfo.java:166)
at org.codehaus.groovy.reflection.ClassInfo.getMetaClass(ClassInfo.java:182)
at org.codehaus.groovy.runtime.metaclass.MetaClassRegistryImpl.getMetaClass(MetaClassRegistryImpl.java:227)
at org.codehaus.groovy.runtime.InvokerHelper.getMetaClass(InvokerHelper.java:751)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.createCallStaticSite(CallSiteArray.java:59)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.createCallSite(CallSiteArray.java:146)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:42)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:108)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:112)
at com.fullcontact.elasticsearchtests.TestHarness.queryElasticSearch(TestHarness.groovy:27)

@kimchy
Copy link
Member

kimchy commented Feb 21, 2013

@danklynn which groovy version?

@pablomolnar
Copy link

@kimchy The issue is pretty issue to reproduce in Grails 2.2.1

  1. grails create-app bug
  2. Add inside the dependecy block in the BuildConfig.groovy:
    compile 'org.elasticsearch:elasticsearch:0.20.5'
    compile('org.elasticsearch:elasticsearch-lang-groovy:1.3.0')
  1. Add this unit test:

class ClassNotFoundTests {

void testBug() {
    org.elasticsearch.index.query.QueryBuilders.matchAllQuery()
}
  1. grails test-app report:

Running 1 unit test... 1 of 1
| Failure: testBug(bug.ClassNotFoundTests)
| java.lang.NoClassDefFoundError: com/spatial4j/core/shape/Shape
at java.lang.Class.privateGetDeclaredMethods(Class.java:2451)
at java.lang.Class.getDeclaredMethods(Class.java:1810)
at org.codehaus.groovy.util.LazyReference.getLocked(LazyReference.java:46)
at org.codehaus.groovy.util.LazyReference.get(LazyReference.java:33)
at bug.ClassNotFoundTests.testBug(ClassNotFoundTests.groovy:12)
Caused by: java.lang.ClassNotFoundException: com.spatial4j.core.shape.Shape
at org.codehaus.groovy.tools.RootLoader.findClass(RootLoader.java:175)
at java.lang.ClassLoader.loadClass(ClassLoader.java:423)
at org.codehaus.groovy.tools.RootLoader.loadClass(RootLoader.java:147)
at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
... 5 more
| Completed 1 unit test, 1 failed in 533ms
| Packaging Grails application.....
| Tests FAILED - view reports in /private/tmp/bug/target/test-reports

@pablomolnar
Copy link

Also, FYI the issue is not present using 0.90.0.Beta1:

    compile 'org.elasticsearch:elasticsearch:0.90.0.Beta1'
    compile('org.elasticsearch:elasticsearch-lang-groovy:1.4.0')

@worldsayshi
Copy link

worldsayshi commented Sep 3, 2019

This still seem to happen in Groovy (v 2.4.15) with elasticsearch-6.6.0.

Here's a (probably obvious) workaround: Wrap the method calls in Java:

public class QueryBuildersWrapper {
    public static MatchQueryBuilder matchQuery(String name, Object text) {
        return QueryBuilders.matchQuery(name, text);
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants