My adventure solution
I started my own business, as you can see in my question. Whenever I changed part of my settings, one part started working, but the other part stopped working. Let me give a story of my solution:
1.) By default, I indexed my data. This means that my data is analyzed by default. This will cause a problem on my side. For example:
When the user began to search for a keyword such as SVF-1 , the system launches this query:
{ "query": { "filtered" : { "query" : { "query_string" : { "analyze_wildcard": true, "query": "*SVF-1*" } } } } }
and results;
SVF-123 SVF-234
This is normal because the name field of my documents is analyzed . This splits the request into SVF and 1 tokens, and SVF matches my docs, although 1 doesn't match. I missed this path. I created a mapping for my fields, making them not_analyzed
{ "mappings":{ "product":{ "properties":{ "name":{ "type":"string", "index": "not_analyzed" }, "site":{ "type":"string", "index": "not_analyzed" } } } } }
but my problem continued.
2.) I wanted to try a different path after many studies. Decided to use a group request . My request:
{ "query": { "wildcard" : { "name" : { "value" : *SVF-1*" } } }, "filter":{ "term": {"site":"pro_en_GB"} } } }
This request worked, but there is one problem. My fields are not already parsed, and I'm doing a wildcard query. Case sensitivity is the problem here. If I search like svf-1 , it returns nothing. Since the user can enter a lowercase version of the query.
3.) I changed the structure of my document to;
{ "mappings":{ "product":{ "properties":{ "name":{ "type":"string", "index": "not_analyzed" }, "nameLowerCase":{ "type":"string", "index": "not_analyzed" } "site":{ "type":"string", "index": "not_analyzed" } } } } }
I have another field for name called nameLowerCase . When I index my document, I set my document as follows:
{ name: "SVF-123", nameLowerCase: "svf-123", site: "pro_en_GB" }
Here, I convert the query keyword to lowercase and perform a search operation on the new index nameLowerCase . And displaying the name field.
Final version of my query:
{ "query": { "wildcard" : { "nameLowerCase" : { "value" : "*svf-1*" } } }, "filter":{ "term": {"site":"pro_en_GB"} } } }
Now it works. There is also one way to solve this problem using multi_field . My request contains a dash (-) and is facing some problems.
Many thanks to @Alex Brasetvik for the detailed explanations and efforts.