Laravel elastic search implement soundex - laravel

I'm facing an issue on the elastic search that it's not able to search if someone types wrong spelling. I have done some R & D about Soundex. Now I'm facing an issue to implement Soundex on elastic search. Please help me to do that, I've already installed Phonetic Anaalysis plugin on elastic search but how to configure the plugin with elastic search that will work with the search results.
'title' => [
'type' => 'text',
'analyzer' => $language . '_analyzer',
'index' => true,
'norms' => false,
'term_vector' => 'with_positions_offsets',
'fields' => [
'raw' => [
'type' => 'keyword',
'normalizer' => 'lowercase_normalizer',
'index' => true,
'norms' => false,
],
],
],

You need to create a custom analyzer using phonetic token filter and the apply this custom analyzer to your text field.
Alternatively, if you want to search with mistypes you can use fuzzy matches.

Related

How to repair ElasticSearch broken query?

When I upgrade SSL my elasticsearch has stopped working and do not know why?
$params = [
'index' => 'vf_dev',
'size' => $filter["limit"],
'from' => $filter["skip"],
'body' => [
'query' => [
'bool' =>
$search
]
]
];
My query is like above. My error is lilke below. What am I missing?
{"type":"x_content_parse_exception","reason":"[1:93] [bool] failed to parse field [must]"}],"type":"x_content_parse_exception","reason":"[1:93] [bool] failed to parse field [must]","caused_by":{"type":"illegal_state_exception","reason":"Can't get text on a START_ARRAY at 1:93
Tldr
I believe, your pattern for a boolean query is wrong.
As per the documentation you should have either:
filter
must
should
must_not
I believe it is missing.

Elasticsearch Aggregation using Nested returns empty buckets

Elasticsearch: v7.2
Application: Laravel v.5.7
Hello and good day! I'm using Elasticsearch to make a report of my documents, I stumbled upon the need of presenting data fields that are nested in nature.
I have the following mappings, I have my index web with a field called ent:
Now I have the following query, using the aggs, my goal is to present the entities that have the MOST counts that can be found in my documents:
'aggs' => [
'ENT' => [
'nested' => [
'path' => 'ent'
],
'aggs' => [
'TOP_ENTITIES' => [
'terms' => [
'field' => 'ent.ent_count'
]
]
]
]
]
What I'm finding weird about this, is that when I'm targeting the ent.ent_count field, the buckets works perfectly fine, finding the distinct ent_count together with its respective doc_counts which portrays the total number of occurence of that ent_count:
BUT when I'm targeting the ent.ent_name field, it returns empty:
'aggs' => [
'ENT' => [
'nested' => [
'path' => 'ent'
],
'aggs' => [
'TOP_ENTITIES' => [
'terms' => [
'field' => 'ent.ent_name.keyword'
]
]
]
]
]
RESULTS TO
With non-nested fields, this works perfectly fine, am I doing something wrong with my query? because even the examples from the documentation shows the same scripts
There's no other way to solve this problem unless you change the mappings
So instead of letting the ent.ent_name nested field to be of text field, we have found out that short words in nested fields should be of KEYWORD type:
After changing the _mappings to keyword, everything worked perfectly fine

How we can integrate Elastic search in yii2 project

How do we implement elastic search in yii2. Done with installation, How do I search by database using elastic search?
This is my config file:
'components' => [
'elasticsearch' => [
'class' => 'yii\elasticsearch\Connection',
'nodes' => [
['http_address' => '127.0.0.1:80'],
],
],
Hope the below link give u some idea about it
http://voormedia.com/blog/2014/06/four-ways-to-index-relational-data-in-elasticsearch

CakePHP 3 - How to apply validation conditionally?

Trying to restrict a compareWith to just on create
$validator->add('password', [
'compare' => [
'rule' => ['compareWith', 'password_confirmation']]]);
I cant seem to work out how to do it added 'create' to the end like
$validator->add('password', [
'compare' => [
'rule' => ['compareWith', 'password_confirmation']]],'create');
in fact i have tried the 'create' in many places either build errors or still validating on an edit
Appreciate any help
Try this:
$validator->add("password", "compare", [
"rule" => ["compareWith", "password_confirmation"],
"message" => __("Password and password confirmation fields don't match."),
"on" => "create"
]);
This will certainly work.
Hope this helps.
Peace! xD

How to sort on analyzed/tokenized field in Elasticsearch?

We're storing a title field in our index and want to use the field for two purposes:
We're analyzing with an ngram filter so we can provide autocomplete and instant results
We want to be able to list results using an ASC sort on the title field rather than score.
The index/filter/analyzer is defined like so:
array(
'number_of_shards' => $this->shards,
'number_of_replicas' => $this->replicas,
'analysis' => array(
'filter' => array(
'nGram_filter' => array(
'type' => 'nGram',
'min_gram' => 2,
'max_gram' => 20,
'token_chars' => array('letter','digit','punctuation','symbol')
)
),
'analyzer' => array(
'index_analyzer' => array(
'type' => 'custom',
'tokenizer' =>'whitespace',
'char_filter' => 'html_strip',
'filter' => array('lowercase','asciifolding','nGram_filter')
),
'search_analyzer' => array(
'type' => 'custom',
'tokenizer' =>'whitespace',
'char_filter' => 'html_strip',
'filter' => array('lowercase','asciifolding')
)
)
)
),
The problem we're experiencing is unpredictable results when we Sort on the title field. After doing a little searching, we found this at the end of the sort man page at ElasticSearch... (http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/search-request-sort.html#_memory_considerations)
For string based types, the field sorted on should not be analyzed / tokenized.
How can we both analyze the field and sort on it later? Do we need to store the field twice with one using not_analyzed in order to sort? Since the field _source is also storing the title value in it's original state, can that not be used to sort on?
You can use the built in concept of Multi Field Type in Elasticsearch.
The multi_field type allows to map several core_types of the same value. This can come very handy, for example, when wanting to map a string type, once when it’s analyzed and once when it’s not_analyzed.
In the Elasticsearch Reference, please look at the String Sorting and Multi Fields guide on how to setup what you need.
Please note that Multi Field mapping configuration has changed between Elasticsearch 0.90.X and 1.X. Use the appropriate following guide based on your version:
0.90 Multi Field Type
1.X Multi Field Type

Resources