Comments (14)
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.
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.
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.
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.
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.
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.
Yes, I think so.
from jest.
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.
Several issues:
- 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.
JestResult.getSourceAsObjectList(MyClass.class);
Method callscreateSourceObject(JsonElement, Class<T>)
, which has an internalGson
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.
- 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?
- 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.
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 JestResult
s with that Gson instance.
from jest.
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.
@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.
Closing issue as this is now resolved in release 0.0.5.
from jest.
Related Issues (20)
- Invalid type conversion Integer -> Double
- Why do not working the index pattern in search request
- Path to hits/total needs to be updated for ESV7 HOT 2
- update by query
- Documentation for Kerberos Authentication
- Geo distance which api can support
- Delete child documents without parent
- Node Discovery Frequency Only send to one node.
- Search query logging
- Support for alias is_write_index
- release of version 6.8.10
- How to exit main thread when executeAsync method execute completed? HOT 1
- Refactor Search to be Generic
- update gson version to latest 2.8.6?
- 在处理jejstId注解时, 注解属性存在父类无法识别
- How to add parameters on '/_search' method like this '/_search?preference=zxcvzxd123'
- io.searchbox.client.http.JestHttpClient#deserializeResponse cause oom exception
- CatResult.parseResultArray throws java.lang.UnsupportedOperationException: JsonNull
- a problem wen upgrading to ES 7
- Is this project dead? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from jest.