golofetuk
(Lacy Rodgers)
December 6, 2022, 8:26am
1
I have a word index and I can't search phrases on elasticsearch. there is no result. I check tons of solutions but I can't implement them to my query.
My mapping looks like this;
PUT /words/_mapping
{
"properties": {
"text": {
"type": "keyword"
}
}
}
(if the type is text everything worked as expected)
My elastic query looks like this;
GET /words/_search
{
"from": 0,
"query": {
"bool": {
"filter": [
{
"bool": {
"should": [
{
"query_string": {
"default_field": "text",
"default_operator": "AND",
"query": "*foo bar baz*"
}
}
]
}
}
]
}
},
"size": 100,
"track_total_hits": true
}
But there is no data
_id
_index
_score
_type
text
I expect the record that has `foo bar baz` value,
_id
_index
_score
_type
text
drDzzYQBu3ncIuw4vn10
words
0.0
_doc
foo bar baz
What is the problem? Could someone help?
You should change your text field type to use text type family, e.g. text or match_only_text instead of keyword.
golofetuk
(Lacy Rodgers)
December 6, 2022, 8:43am
3
I can't change the type because the code will ship to the prod server and I can't modify any prod elastic index. it works on only word searching. Is there any solution I can do?
Your query should match text field containing value foo bar baz.
Try to remove default_operator.
Just a suggestion, but you don't need a nested bool > should within bool > filter, unless if this query is part of a larger query.
golofetuk
(Lacy Rodgers)
December 6, 2022, 9:00am
5
It's a larger query I can't share company material, so I modify the query.
My purpose is to search phrases or words `default_operator' to help to this .
Your query string is matching by phrase because you are using keyword field type.
With a keyword field you’ll need to use a wildcard query but there are some important caveats. This blog should give you all the background Find strings within strings faster with the Elasticsearch wildcard field | Elastic Blog
system
(system)
Closed
January 3, 2023, 12:19pm
8
This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.