sql
sql copied to clipboard
SQL builds query incorrectly, trying to query non existent field
I have a query:
POST _opendistro/_sql
{
"query": "SELECT url FROM index_name WHERE url = 'some_url'"
}
With mapping:
"url" : {
"type" : "keyword",
"ignore_above" : 10922,
"fields" : {
"reverse" : {
"type" : "text",
"analyzer" : "reverse_raw"
}
}
},
But when i run the query it doesn't find anything and _explain shows that it's trying to query url.keyword
which does not exist
"request": """ElasticsearchQueryRequest(indexName=index_name, sourceBuilder={"from":0,"size":200,"timeout":"1m","query":{"term":{"url.keyword":{"value":"some_url","boost":1.0}}},"_source":{"includes":["url"],"excludes":[]},"sort":[{"_doc":{"order":"asc"}}]}, searchDone=false)"""
What do you mean by "url.keyword" doesn't exist?
usually .keyword
is appended to the field name when running a search because it is the object containing the actual data you want to search
@FreCap we have our own mapping for index and we don't analyze url field and we dont create .keyword type separetly.
in your case mapping would look like something like:
"url": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
we have
"url" : {
"type" : "keyword",
"ignore_above" : 10922,
},
but if you look at our mapping our url
field has keyword
type already and it doesn't have .keyword
field separetly. which results in opendistro generating incorrect query.