Reputation: 87
I am fairly new to elasticsearch and I need to use fuzziness in my match_phrase query, but have not found suitable help documents for the same. Since my mapping is also nested, I'm having little trouble to get the right query.
Mapping
{
"mappings":{
"type":{
"properties":{
"Id":{
"type":"integer"
},
"custom":{
"type":"nested",
"properties":{
"text":{
"type":"text"
},
"start_time":{
"type":"text"
},
"end_time":{
"type":"text"
}
}
}
}
}
}
}
POST http://localhost:9200/transcripts/type/_search
{
"query":{
"nested":{
"path":"custom",
"query":{
"match_phrase":{
"custom.text":"search something here",
"fuzziness":"2"
}
},
"inner_hits":{
"highlight":{
"fields":{
"custom.start_time":{}
}
}
}
}
}
}
OUTPUT
{
"error": {
"root_cause": [
{
"type": "parsing_exception",
"reason": "[match_phrase] query doesn't support multiple fields, found [custom.text] and [fuzziness]",
"line": 8,
"col": 26
}
],
"type": "parsing_exception",
"reason": "[match_phrase] query doesn't support multiple fields, found [custom.text] and [fuzziness]",
"line": 8,
"col": 26
},
"status": 400
}
Upvotes: 0
Views: 821
Reputation: 169
It means that your query is malformed. Check out this documentation about match queries: https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-match-query.html
It seems that your nested query should look like this:
{
"query": {
"match" : {
"custom.text" : {
"query" : "search something here",
"fuzziness": "2"
}
}
}
}
So, your query should be:
{
"query":{
"nested":{
"path":"custom",
"query":{
"match":{
"custom.text": {
"query" : search something here",
"fuzziness":"2"
}
}
},
"inner_hits":{
"highlight":{
"fields":{
"custom.start_time":{}
}
}
}
}
}
}
Upvotes: 0