Exact match on some fields and "fuzzy" search on others? - elasticsearch

I am attempting to create a query to exactly match on a few fields, such as account_id and from_addresses (which is an array), while also fuzzy matching on another field such as message_content. What is the best way to do this?
I have tried a Bool query with a few must and should parameters but can't seem to get it working.

I believe what you want to do it to use Filters. More specifically, an AND filter. So your query message_content, but filter by account_id and from_addresses.
I don't know which library you are using, so I can't really provide any code examples.

Related

Elastic Search Query that identifies not only the results but also highlights the items that satisfy a particular attribute

We have a requirement that we think is a candidate for a Multi-Search query but we are not sure.
Say we are selling clothes.
The user can enter a type of clothing such as Shirts and we bring back all the shirts using a filter.
We would also like to provide the user with an option of them typing in a keyword such as "formal" or "beach" etc. But this keyword should not effect the results but identify with a flag which items in the results these keywords appear.
Any suggestion would be greatly appreciated.
What about using Named Queries?
The ideas is that this feature of Elasticsearch allows users to mark each clause in the query with a _name value identifying the particular clause. If the particular clauses, say a clause with "formal" keyword or a clause with "beach" keyword", are matched, the response will include a matched_queries prop with each result noting which particular item was matched.
Another option might be to use Highlights. The feature does allow you to specify a separate highlighting query. However, the response format here may not be as straightforward or meet your requirements.

Solr boost query sort by whether result is boosted then by another field

I'm using Solr to run a query on one of our cores. Suppose my documents have two fields: ID, and Name. I also have a separate list of IDs I'm grabbing from a database and passing into the query to boost certain results.
If the document gets returned in the query and the ID is in the list it goes to the top of the results, and if it gets returned in the query and the ID is not in the list then it goes below those that are in the list. The former is from the "boost". My query is something like this -
http://mysolrserver:8983/solr/MyCore/MyQueryHandler?q=Smith&start=0&rows=25&bq=Id%3a(36+OR+76+OR+90+OR+224+OR+391)
I am able to get the boost query working but I need the boosted results to be in alphabetical order by name, then the non boosted results under that also in alphabetical order by name. I need to know what to user for the &sort= parameter.
&sort=score%20desc,Name+asc does not work.
I've looked over a lot of documentation, but I still don't know if this even possible. Any help is appreciated. Thanks!
Solr version is 6.0.1. I am actually using SolrNet to interface with Solr, but I think I can figure out the SolrNet part if I know what the url's &sort= parameter value needs to be.
I figured it out, by doing away with the boost query. I added a sort query using the "exists" function and passing it a sub-query for the ID. The exists returns a boolean value to sort on, then I added the name as a second sort. It works perfect!!
The URL looks like this:
http://mysolrserver:8983/solr/MyCore/MyQueryHandler?q=Smith&start=0&rows=25&sort=exists(query({!v=%27Id:(36+OR+76+OR+90+OR+224+OR+391)%27}))%20DESC,%20Name%20ASC
The closest match to your requirement is the query elevation component[1] .
In your particular case I would first sort my Ids according to my requirements ( sorting them by name for example), then maintain them in the elevate.xml.
At query time you can use the "forceElevation" parameter to force the elevation and then sort the remaining results by name.
[1] https://cwiki.apache.org/confluence/display/solr/The+Query+Elevation+Component

Elasticsearch, how to make a query that matches strings with spaces

I am in learning process of ElasticSearch and having hard time matching certain cases.
For example I have product name: "SkyProdigy 130" and I am trying to write a query that will match this product name when someone types "sky prodigy". Also, another example for the manufacturer "Magpul" I would like to be able to match even if someone type "mag pul", etc.
I have managed to make this work with fuzzy query, but I am looking for a more organic way to achieve this through analyzers and correct mappings.
Can someone recommend the best approach for this case?

Can I use filters to annotate matches in elasticsearch

When I do a search on Elasticsearch, I want to have a filter that can indicate which of the results matched the filter and which ones didn't.
Is there a way to use a filter (or something that works similarly) that doesn't filter, but instead reports?
I use a pretty complex filter to remove results, but I would rather have the filtered results differentiated from ones that didn't match the filter. I could do it with multiple queries, but that seems wasteful.
Is named queries and filters what you want?
I can interpret your need in a few ways, so I'm not entirely sure. Maybe you could have a tautology filter with named sub-filters.

ElasticSearch / Tire & Keywords. Right way to match "or" for a keyword list?

I've got an Entity model (in Mongoid) that I'm trying to search on its keywords field which is an array. I want to do a query where I pass in an array of potential search terms, and any entity that matches any of the terms will pass.
I don't have this working well yet.
But, why I'm asking this question, is that it's more complex. I also DONT want to return any entities that have been marked as "do not return" which I do via a "ignore_project_ids" parameter.
So, when I query, I get 0 results. I was using Bonsai.io. But, I've moved this to my own EC2 instance to reduce complexity/variables on solving the problem.
So, what am I doing wrong? Here are the relevant bits of code.
https://gist.github.com/3405763
You want a terms query rather than a term query - a term query is only interested in equality, whereas a terms query requires that the field match any of the specified values.
Given that you don't seem to care about the query score (you're sorting by another attribute), you'll get faster queries by using a filtered query and expressing your conditions as filters

Resources