How can I write aggregation query on a particular term in hibernate search using elastic search.Is there any way to do this?
If you are looking to perform faceting (which is one way of using aggregations), Hibernate Search provides a dedicated feature: https://docs.jboss.org/hibernate/stable/search/reference/en-US/html_single/#query-faceting
If you want to aggregate for other purposes, I'm afraid this is not possible (yet) using Hibernate Search. We are planning to introduce it in Hibernate Search 6, though (or at least allow to perform aggregations by bypassing Hibernate Search's abstractions).
Related
We are using hibernate search api for elastic search. I came across lenient option in elastic search: https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-query-string-query.html but unable to figure out how can we set this through hibernate search.
Some of the fields in elastic search are boolean, and range, and we don't want to search through them.
There is no such option in Hibernate Search at the moment.
In Hibernate Search 5, you can write your whole query as JSON in order to take advantage of native options. That will require you to write everything as JSON, though, not just the simple-query-string query.
In Hibernate Search 6, you write just the simple-query-string predicate as JSON to take advantage of a native option in this predicate and continue using the Hibernate Search DSL for other predicates in the same query, which should be more convenient.
If you need the feature in the DSL, you can create a JIRA ticket and it will be addressed in Hibernate Search 6 if it makes it to the top of the priority list. If you need it before then, you can of course submit a pull request. Note that new features should go into Hibernate Search 6 (master branch), not Hibernate Search 5 which is currently in maintenance mode.
Is it possible to execute match_phrase_prefix in using hibernate search Query? I did not find any appropriate query class so far. I also don't want user ElasticsearchQueries.fromJson since I need to combine different conditions using bool
If you do not want to use ElasticsearchQueries.fromJson, then no, it's not possible to do that through the Hibernate Search APIs. That's a limitation of the experimental support for Elasticsearch in Hibernate Search 5.
It will be possible in Hibernate Search 6, but it's still an Alpha.
I'm using Hibernate Search for Elasticsearch (5.8.2.Final) and Elasticsearch (6.0). I'm new Hibernate Search and I'm aware that Hibernate Search for Elasticsearch is experimental. I'm also aware that Hibernate 6 is going to bring some improvements for use with ES. However, in the meantime, i'm finding that the annotations are not allowing me to create the types of index mappings i want and I was wondering if there was a way to disable the creation of the index mapping entirely. I'd like to allow ES to apply an index template to my index when Hibernate first creates it. I've read the docs and stepped through the code but I am not seeing anything that would allow me to do this. Is this possible?
Thank you.
You can disable index and mapping creation altogether (see Sanne's answer), but you cannot currently ask Hibernate Search to create indexes without creating mappings.
One solution would be for you to create your indexes beforehand. After all, if you're fine with adding templates, why not add the indexes too?
Another solution: you could try the update strategy. If your custom mapping is compatible with the one generated by Hibernate Search, they might simply get merged. Be careful not to use this in production though, since a failure with the update strategy will leave you in deep trouble (see the warnings in the documentation).
To skip creating the index definitions:
hibernate.search.default.elasticsearch.index_schema_management_strategy none
See also 11.3.4. Hibernate Search configuration
I user Hibernate as well as the Grails Searchable Plugin which is based on Lucene and Compass. I was wondering when I should use what for querying objects from the database.
Is there a rule of thumb when to use Hibernate and when to user Searchable?
Searcable plugin will be highly useful when you think of free form text search through out your application.
To cite an example, if you are working on a banking application and you are building a portal with a search feature. And you want the search to be free form for all the key elements like customer name, ssn, phone number and/or email id, then you would like to index those using searchable and provide the search talking to searchable to get immediate search results. For this to happen you would have to index those key elements at the least. The indices would grow as ans when you add more key search elements.
On the other hand, hibernate will help you provide the detail information if you do not want to index lot of elements. To extend the above example, once you did a search on SSN and you got a hit, on selecting that entry you can use hibernate to fetch the detail information from the underlying persistence layer using hibernate.
Inference:
For speedy, high performance, free form search searhable is an option.
For gathering detailed information, post the search, I think hibernate is the way to go unless you want to use searchable for the detail info as well in which case the size of the indices will be in Gigs.
Follow here in elastic search which might help to understand.
My point is to make elastic/searchable lighter keeping the heavy lifting part taken care by hibernate.
NOTE
On a side note, I would suggest using elastic instead of searchable. It has also got a groovy API which is useful. Also note that elastic plugin uses v0.20.0 version of elastic search right now, the latest one being v0.90.2 I guess. If required you can directly use elastic search as a dependency and get the latest feature.
I know there is a built-in DuplicateFilter in Lucene, to deduplicate the results from lucene. This is a very important feature for the users to search on the document database, where duplicating rate is very high.
As I am using Hibernate Search to do the full text index/search, and wondering if there is a way for me bring the DuplicateFilter on Lucene to the Hibernate Search?
It is possible by using filters. See for BestDriversFilter - it extends org.apache.lucene.search.Filter in the same way as DuplicateFilter.