Punctuation with wildcard search in Elasticsearch - elasticsearch

I have a custom analyzer on field authlast that replaces punctuation with space. So when search with saint-, I am able to get results, but when I search with saint-* I get no results. Any idea why?
How does query_string analyze the string before submitting it for the search? If it does not analyze how does the term looks like when query_string submits the term to the ES index?
$"query": {
{
"query_string": {
"query": "saint-*",
"fields": ["authlast"],
"default_operator": "AND"
}
}
}
window.jQuery.

Related

fuzziness in elastic search search by letter not by word

Hey I am trying to make a fuzzy search in Elasticsearch I write this query
"query": {
"match": {
"NAME": {
"query": "data" ,
"fuzziness": "AUTO"
}
}
}
but it keeps return the best match on word not the nearest letter
what I need is actually near to google search any idea ?

Elastic Search: query_string query does not match exact phrase in full text search

I am using Elastic search 6.2.3. We are using the query_string full-text-query for the full-text search. At present, if we search lazy brown fox it searches any file that has all these words lazy, brown and fox but it does not look for exact-phrase 'lazy brown fox', even default slop is zero.
Here is an example:
{
"query": {
"query_string": {
"fields": [],
"query": "lazy AND brown AND fox"
}
}
}
I have looked at the match-phrase-query but the issue is that we have to specify the field name(s) in match-phrase-query whereas, in string-query, it's working with a blank array at fields option.
Please suggest, how to get the exact phrase match results using query_string full text-query?
Instead of looking at match-phrase query to run phrase query on multiple fields take a look at multi_match which do supports phrase type query
POST phrase_index/_search
{
"query": {
"multi_match": {
"query": "this is where it should work",
"fields": [],
"type": "phrase"
}
}
}

ANDing search keywords for elastic Search

How can we configure elastic search so that it only returns results which matches all the words in the search query. The documents indexed have data having multiple fields and so the words of search query may match different fields of data but all the words must get matched in the result ?
you can query string query feature to search for results
sample search query
GET /_search
{
"query": {
"query_string": {
"query": "(content:this OR name:this) AND (content:that OR name:that)"
}
}
}
In this query content and name is the field name, this is the search criteria
you can build search query similar to that.
I think you're looking for a multi_match query together with and operator. This is the link to docs: https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-multi-match-query.html and it seems that cross_fieldsis query type you're looking for. I'd read more on that page, but this is probably what you are looking for:
GET /_search
{
"query": {
"multi_match" : {
"query": "Will Smith",
"type": "cross_fields",
"fields": [ "first_name", "last_name" ],
"operator": "and"
}
}
}

Wildcard search on chinese/japanese characters in Elasticsearch

I indexed a text containing chinese words in elastic using default analyzer. My text contains 聲譽 which means reputation in chinese.
When I apply a wildcard search using (?) e.g. 聲? or ?譽 I do not get any results.
However a wildcard search using (*) e.g. 聲* or *聲 return results.
Is this how it is supposed to work?
Here's my query:
{
"_source": ["content_id"],
"size": 10,
"query": {
"query_string": {
"default_field": "txt_1",
"query": "聲?"
}
}
}

Elasticsearch: multi_match phrase_prefix query with multiple search terms

I have a database with entries like
title: This is my awesome title
abstract: A more detailed descriptions of what [...]
I would like to build an Elasticsearch query that matches the above document with, e.g.,
awe detai
In words: A multi_match phrase_prefix query with multiple search terms. (This is intended to be used as a search-as-you-type feature.)
I see how you can combine multi_match and phrase_prefix, but it's unclear to me how to do this for multiple search terms.
Any hints?
Well there is few ways to do that
POST stack/autocomplete/1
{
"title": "This is my awesome title",
"abstract": "A more detailed descriptions of what"
}
Then you can search using query string with star but problem here is that you need to append asterix to query
POST stack/autocomplete/_search
{
"query": {
"query_string": {
"fields": [
"title",
"abstract"
],
"query": "awe* detai*"
}
}
}
If you want to match on user query then you can use like that
POST stack/autocomplete/_search
{
"query": {
"multi_match": {
"fields": [
"title",
"abstract"
],
"query": "awesome tit",
"type": "phrase_prefix"
}
}
}
One more option to consider would be to use nGram with query string so you will not need to modify user query "awe* detai*"

Resources