Search for non indexed fields is not working Please help

Hello,

I want to filter the search results using non indexed field.

{
"_index" : "shipmentdata_v1",
"_type" : "_doc",
"_id" : "128Q711U",
"_score" : 1.0,
"_source" : {
"bundleId" : 13663,
"customerId" : 101456
}
}
for example customer Id.

I used below and it gives me an exception:
{

"query": { "match": { "customerId": 129759 } }
}
'

{
"error" : {
"root_cause" : [
{
"type" : "query_shard_exception",
"reason" : "failed to create query: {\n "match" : {\n "customerId" : {\n "query" : 129759,\n "operator" : "OR",\n "prefix_length" : 0,\n "max_expansions" : 50,\n "fuzzy_transpositions" : true,\n "lenient" : false,\n "zero_terms_query" : "NONE",\n "auto_generate_synonyms_phrase_query" : true,\n "boost" : 1.0\n }\n }\n}",
"index_uuid" : "2lkJMMvNQju8HmwMvPeo3A",
"index" : "shipmentdata_v1"
}
],
"type" : "search_phase_execution_exception",
"reason" : "all shards failed",
"phase" : "query",
"grouped" : true,
"failed_shards" : [
{
"shard" : 0,
"index" : "shipmentdata_v1",
"node" : "uGsbj81VRGmgHjgG4bgkKA",
"reason" : {
"type" : "query_shard_exception",
"reason" : "failed to create query: {\n "match" : {\n "customerId" : {\n "query" : 129759,\n "operator" : "OR",\n "prefix_length" : 0,\n "max_expansions" : 50,\n "fuzzy_transpositions" : true,\n "lenient" : false,\n "zero_terms_query" : "NONE",\n "auto_generate_synonyms_phrase_query" : true,\n "boost" : 1.0\n }\n }\n}",
"index_uuid" : "2lkJMMvNQju8HmwMvPeo3A",
"index" : "shipmentdata_v1",
"caused_by" : {
"type" : "illegal_argument_exception",
"reason" : "Cannot search on field [customerId] since it is not indexed."
}
}
}
]
},
"status" : 400
}

I also tried to use

{

"filter": {
"script": {
"script": "_source['customerId'].value == 129759"
}
}
}

but it gave below exception:

{
"error" : {
"root_cause" : [
{
"type" : "parsing_exception",
"reason" : "Unknown key for a START_OBJECT in [filter].",
"line" : 3,
"col" : 11
}
],
"type" : "parsing_exception",
"reason" : "Unknown key for a START_OBJECT in [filter].",
"line" : 3,
"col" : 11
},
"status" : 400
}

1、Search can not perform on fields that not index ( index mapping field setting "index: false" )

solution: reindex ur index with setting field setting "index: true"

2、Ur query body is illegal, syntax of "filter" should not be use in that way...

Thank you for quick response.

Since I am new to elastic search I tried different solutions from Google and applied here. Could you please let me know the correct syntax for filter. I am trying in different ways but unable to make it work.

Do u mind parse the query body that not work here, so we can figure out the problem and correct it directly?

And also, u can follow this tutor to create ur own query body for searching which i think, is more friendly to new user than es ref.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.