Coder Social home page Coder Social logo

Comments (14)

kramer avatar kramer commented on July 26, 2024
 ssb.query(QueryBuilders.rangeQuery("timestamp").from(from).to(to));

With this line you are bypassing the Jest's serialization process and using the Elasticsearch API's QueryBuilder for it; so your custom Gson instance is never even taken into account.

This would work as expected (although not the most elegant):

Map<String, Object> innerMap = new HashMap<String, Object>();
innerMap.put("from", fromDateInstance);
innerMap.put("to", toDateInstance);
innerMap.put("include_lower", true);
innerMap.put("include_upper", true);

Map<String, Object> rangeMap = new HashMap<String, Object>();
rangeMap.put("timestamp", innerMap);

Map<String, Object> query = new HashMap<String, Object>();
query.put("range", rangeMap);

ssb.query(query);

from jest.

churro-s avatar churro-s commented on July 26, 2024

Hello, thank you for your answer. I completely forgot that QueryBuilder is part of the Elasticsearch API, and not Jest.

I tried your solution, but my Dates ended up in the same format because whether I pass a Map or a QueryBuilder, all values get serialized in the XContentBuilder class, which uses an internal DateTimeFormatter:

org.elasticsearch.common.xcontent.XContentBuilder.writeValue(Object);

I guess my solution is to not use SearchSourceBuilder.toString() because that creates a default XContentBuilder.

I'll update the post with my results.

from jest.

kramer avatar kramer commented on July 26, 2024

ah sorry, for a second i though your "ssb" object was a Jest class :) well if it's not then the code piece i posted earlier won't work either...

from jest.

churro-s avatar churro-s commented on July 26, 2024

Yeah. As I just figured out, XContentBuilder cannot be extended (it's finalized). It seems I will have to create a Mapping to configure my Date formats.

from jest.

kramer avatar kramer commented on July 26, 2024

You could also extend Jest's Search action class to accept Object as query parameter. AbstractAction already uses Object class as data/query property so JestHttpClient will use the custom Gson instance to serialize it.
You'll need to i) change the Search.Builder's constructor to accept Object class as query and ii) change the private Search constructor accordingly.

from jest.

churro-s avatar churro-s commented on July 26, 2024

So if I make a custom Search(Object) class to avoid using SearchSourceBuilder.toString(), I would have to pass it a Map with all my query parameters in it (like in your previous comment), right?

from jest.

kramer avatar kramer commented on July 26, 2024

Yes, I think so.

from jest.

churro-s avatar churro-s commented on July 26, 2024

Thank you, I think that solution will work for me. I ran into this issue #68, so I will post my results after I update and build Jest.

from jest.

churro-s avatar churro-s commented on July 26, 2024

Several issues:

  1. Building from source failed (I ran mvn package):
Tests run: 13, Failures: 1, Errors: 0, Skipped: 0, Time elapsed: 0.869 sec <<< FAILURE!
bulkOperationWithCustomGson(io.searchbox.core.BulkIntegrationTest)  Time elapsed: 0.105 sec  <<< FAILURE!
junit.framework.AssertionFailedError: expected:<2013-**-01> but was:<2012-**-12>
...
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.7.2:test (default-test) on project jest: There are test failures.
  1. JestResult.getSourceAsObjectList(MyClass.class); Method calls createSourceObject(JsonElement, Class<T>), which has an internal Gson instance that I can't override.

My custom class has a Map<String, String>, which gets de-serialized by that Gson instance as a com.google.gson.internal.LinkedHashTreeMap. I want it to de-serialize as a plain old HashMap.

I know you guys are working on centralizing the Gson config throughout Jest. Is there any way I can help expedite the process? It is now becoming an issue for my project.

from jest.

kramer avatar kramer commented on July 26, 2024
  1. I think that test failure indicates a time-zone problem but the test code creates the Date object using a long number (epoch time) so a time-zone related confusion should not be possible thus I can't reproduce it. Maybe it is caused by some line you changed, can you debug and see where things go wrong?
  2. You are right, JsonResult should use the Action's Gson instance, of which it is the result for. This would (most likely) mean changing the Action interface/implementations and/or the client class; which brings us to the centralized Gson instance/config issue. I'm preoccupied with daytime work nowadays so I won't be able to contribute on that matter this week but feel free to share your ideas & pull requests.

p.s.: sorry for the late reply.

from jest.

churro-s avatar churro-s commented on July 26, 2024

Hey, thanks for the response! I was able to get the test working and built myself a working version from source. I did it using a Calendar instance (Hope this doesn't break the purpose of the test):

Calendar c = Calendar.getInstance();
c.set(2013, 0, 1);
source.put("user", c.getTime()); // Tue, 01 Jan 2013 00:00:00 GMT

I also modified the local copy of my code to pass the Gson instance from ClientConfig over to AbstractJestClient which will create JestResults with that Gson instance.

from jest.

kramer avatar kramer commented on July 26, 2024

This issue should now be resolved by commits 7f7dedc and 9669d68 (which are now included in release 0.0.5 :) ), can you confirm?

from jest.

churro-s avatar churro-s commented on July 26, 2024

@kramer, thanks for the notification. I had forked the old code and used a custom build temporarily, so I will use your new code in the coming week. I will report back with results when I do.

from jest.

kramer avatar kramer commented on July 26, 2024

Closing issue as this is now resolved in release 0.0.5.

from jest.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.