I am new to ElasicSearch and was thrown into a project using it and I have a question about searching. We'd like to implement a "Contains()" type of search on a particular field like C# offers. I found something promising in this post however it is not working and just returns all results. Basically, we want to search the "meta_keywords" and return any results where it contains a string, for example "product". I have tried this based on the link I looked at:
{
"query": {
"query_string": {
"default_field": "meta_keywords",
"query": "*product*"
}
}
}
However, this query just returns all the results and doesn't seem to filter out anything.
I haven't found any documentation on their site about this so not sure I am doing it correctly. Also, I'd like it to be case insensitive if possible. Also a link to their documentation would be helpful as well.
Thanks
I am new to ElasicSearch and was thrown into a project using it and I have a question about searching. We'd like to implement a "Contains()" type of search on a particular field like C# offers. I found something promising in this post however it is not working and just returns all results. Basically, we want to search the "meta_keywords" and return any results where it contains a string, for example "product". I have tried this based on the link I looked at:
{
"query": {
"query_string": {
"default_field": "meta_keywords",
"query": "*product*"
}
}
}
However, this query just returns all the results and doesn't seem to filter out anything.
I haven't found any documentation on their site about this so not sure I am doing it correctly. Also, I'd like it to be case insensitive if possible. Also a link to their documentation would be helpful as well.
Thanks
Share Improve this question edited Mar 20 at 15:07 JimboJones asked Mar 19 at 20:24 JimboJonesJimboJones 1318 silver badges18 bronze badges 1 |1 Answer
Reset to default 0Tldr;
This should do the trick
Demo
I create an index with default mapping and analyzer
POST 79521320/_bulk
{"index":{}}
{"meta_keywords":"I sell good products"}
{"index":{}}
{"meta_keywords":"You know for search"}
{"index":{}}
{"meta_keywords":"Wh have been hanging out for days"}
{"index":{}}
{"meta_keywords":"I hate to smoke"}
GET 79521320/_search
{
"query": {
"query_string": {
"default_field": "meta_keywords",
"query": "*product*"
}
}
}
The search query gives me only one results.
{
"took": 2,
"timed_out": false,
"_shards": {
"total": 1,
"successful": 1,
"skipped": 0,
"failed": 0
},
"hits": {
"total": {
"value": 1,
"relation": "eq"
},
"max_score": 1,
"hits": [
{
"_index": "79521320",
"_id": "PYrQ15UBtnCwjdJLMoii",
"_score": 1,
"_source": {
"meta_keywords": "I sell good products"
}
}
]
}
}
meta_keywords
field – G0l0s Commented Mar 22 at 8:04