i am working with elasticsearch and i wnat to do this type of query
{"query": {"simple_query_string":{"fields":["field1","field2","field3","field4"],"query":"200 100 false message"}}}
and i have field1,field2 of type int and field3 bolean and field4 string
the problem is that elasticsearch will always return parsing error as he will try to compare for rxample field3 with 100
any working solution for this
0
votes
3 Answers
0
votes
According to the Elasticsearch documentation, you can add a lenient argument at true, to ignore format-based errors.
0
votes
Does it matter which field has matched the result? If not you could use copy_to functionality to copy all the text to a single text field, and search on that one! Like so:
PUT stackoverflow
{
"mappings": {
"properties": {
"field1": {
"type": "integer",
"copy_to": "all_fields"
},
"field2": {
"type": "integer",
"copy_to": "all_fields"
},
"field3": {
"type": "text",
"copy_to": "all_fields"
},
"field4": {
"type": "text",
"copy_to": "all_fields"
},
"all_fields": {
"type": "text"
}
}
}
}
And the query:
GET stackoverflow/_search
{
"query": {
"simple_query_string": {
"fields": [
"field_all"
],
"query": "200 100 false message"
}
}
}
0
votes
Adding a working example with index data, mapping, search query and search result
Index Mapping:
{
"mappings": {
"properties": {
"field1": {
"type": "integer"
},
"field2": {
"type": "integer"
},
"field3": {
"type": "boolean"
},
"field4": {
"type": "text"
}
}
}
}
Index Data:
{
"field1": 200,
"field2": 100,
"field3": "false",
"field4": "message"
}
Search Query:
{
"query": {
"simple_query_string": {
"fields": [
"field1",
"field2",
"field3",
"field4"
],
"query": "200 100 false message",
"lenient": true
}
}
}
Search Result:
"hits": [
{
"_index": "66986084",
"_type": "_doc",
"_id": "1",
"_score": 2.575364,
"_source": {
"field1": 200,
"field2": 100,
"field3": "false",
"field4": "message"
}
}
]