How to enable elastic search textfield using java code


(saranjeet) #1

{"from":0,"size":250,"query":{"bool":{"must":[{"match_all":{"boost":1.0}},{"bool":{"must":[{"terms":{"msid":["-1"],"boost":1.0}}],"adjust_pure_negative":true,"boost":1.0}}],"adjust_pure_negative":true,"boost":1.0}},"_source":{"includes":["-4","-3","-5","-6","4421","-7","100","61d","65d","-1","64d","4872d","2432","2434d","2433","1","2","5","4","1746","6","1989","50","2367","4419","4420","msid"],"excludes":},"sort":[{"-5":{"order":"asc","unmapped_type":"long"}}]}

Question-:when i am trying to execute this query, after conversion from java code to elastic search query it is throwing this exception

{
"error": {
"root_cause": [
{
"type": "illegal_argument_exception",
"reason": "Fielddata is disabled on text fields by default. Set fielddata=true on [-5] in order to load fielddata in memory by uninverting the inverted index. Note that this can however use significant memory. Alternatively use a keyword field instead."
}
],
"type": "search_phase_execution_exception",
"reason": "all shards failed",
"phase": "query",
"grouped": true,
"failed_shards": [
{
"shard": 0,
"index": "panaraylistmgrindextesttest-v1",
"node": "TSXGX4urRCqSNLDqFwepXQ",
"reason": {
"type": "illegal_argument_exception",
"reason": "Fielddata is disabled on text fields by default. Set fielddata=true on [-5] in order to load fielddata in memory by uninverting the inverted index. Note that this can however use significant memory. Alternatively use a keyword field instead."
}
}
],
"caused_by": {
"type": "illegal_argument_exception",
"reason": "Fielddata is disabled on text fields by default. Set fielddata=true on [-5] in order to load fielddata in memory by uninverting the inverted index. Note that this can however use significant memory. Alternatively use a keyword field instead.",
"caused_by": {
"type": "illegal_argument_exception",
"reason": "Fielddata is disabled on text fields by default. Set fielddata=true on [-5] in order to load fielddata in memory by uninverting the inverted index. Note that this can however use significant memory. Alternatively use a keyword field instead."
}
}
},
"status": 400
}


(saranjeet) #2

i found this solution for above ,but it is throwing an exception

{
"properties": {
"-2": {
"type": "text",
"fielddata": true
},
"-5": {
"type": "text",
"fielddata": true
},
"-6": {
"type": "text",
"fielddata": true
},
"-7": {
"type": "text",
"fielddata": true
},
"4": {
"type": "text",
"fielddata": true
},
"5": {
"type": "text",
"fielddata": true
},
"50": {
"type": "text",
"fielddata": true
},
"51": {
"type": "text",
"fielddata": true
},
"55": {
"type": "text",
"fielddata": true
},
"100": {
"type": "text",
"fielddata": true
},
"110": {
"type": "text",
"fielddata": true
},
"111": {
"type": "text",
"fielddata": true
},
"497": {
"type": "text",
"fielddata": true
},
"538": {
"type": "text",
"fielddata": true
},
"1607": {
"type": "text",
"fielddata": true
},
"1666": {
"type": "text",
"fielddata": true
},
"1700": {
"type": "text",
"fielddata": true
},
"1705": {
"type": "text",
"fielddata": true
},
"1709": {
"type": "text",
"fielddata": true
},
"1737": {
"type": "text",
"fielddata": true
},
"1979": {
"type": "text",
"fielddata": true
},
"2002": {
"type": "text",
"fielddata": true
},
"2027": {
"type": "text",
"fielddata": true
},
"2047": {
"type": "text",
"fielddata": true
},
"2050": {
"type": "text",
"fielddata": true
},
"2051": {
"type": "text",
"fielddata": true
},
"2060": {
"type": "text",
"fielddata": true
},
"2111": {
"type": "text",
"fielddata": true
},
"2162": {
"type": "text",
"fielddata": true
},
"2324": {
"type": "text",
"fielddata": true
},
"2350": {
"type": "text",
"fielddata": true
},
"2367": {
"type": "text",
"fielddata": true
},
"2371": {
"type": "text",
"fielddata": true
},
"2378": {
"type": "text",
"fielddata": true
},
"2421": {
"type": "text",
"fielddata": true
},
"2433": {
"type": "text",
"fielddata": true
},
"2436": {
"type": "text",
"fielddata": true
},
"2437": {
"type": "text",
"fielddata": true
},
"2440": {
"type": "text",
"fielddata": true
},
"2442": {
"type": "text",
"fielddata": true
},
"2463": {
"type": "text",
"fielddata": true
},
"2515": {
"type": "text",
"fielddata": true
},
"2522": {
"type": "text",
"fielddata": true
},
"2524": {
"type": "text",
"fielddata": true
},
"4419": {
"type": "text",
"fielddata": true
},
"4420": {
"type": "text",
"fielddata": true
},
"4421": {
"type": "text",
"fielddata": true
},
"4505": {
"type": "text",
"fielddata": true
},
"4507": {
"type": "text",
"fielddata": true
},
"4512": {
"type": "text",
"fielddata": true
},
"4513": {
"type": "text",
"fielddata": true
},
"4514": {
"type": "text",
"fielddata": true
},
"4623": {
"type": "text",
"fielddata": true
},
"4624": {
"type": "text",
"fielddata": true
},
"4876": {
"type": "text",
"fielddata": true
},
"4877": {
"type": "text",
"fielddata": true
},
"4878": {
"type": "text",
"fielddata": true
},
"4885": {
"type": "text",
"fielddata": true
},
"4886": {
"type": "text",
"fielddata": true
},
"4898": {
"type": "text",
"fielddata": true
},
"4899": {
"type": "text",
"fielddata": true
},
"6061": {
"type": "text",
"fielddata": true
},
"6062": {
"type": "text",
"fielddata": true
},
"6063": {
"type": "text",
"fielddata": true
},
"6064": {
"type": "text",
"fielddata": true
},
"6065": {
"type": "text",
"fielddata": true
},
"6066": {
"type": "text",
"fielddata": true
},
"6067": {
"type": "text",
"fielddata": true
},
"6068": {
"type": "text",
"fielddata": true
},
"6069": {
"type": "text",
"fielddata": true
},
"6070": {
"type": "text",
"fielddata": true
},
"6071": {
"type": "text",
"fielddata": true
},
"6072": {
"type": "text",
"fielddata": true
},
"6049": {
"type": "text",
"fielddata": true
},
"6050": {
"type": "text",
"fielddata": true
},
"6051": {
"type": "text",
"fielddata": true
},
"6052": {
"type": "text",
"fielddata": true
},
"6053": {
"type": "text",
"fielddata": true
},
"6054": {
"type": "text",
"fielddata": true
},
"6055": {
"type": "text",
"fielddata": true
},
"6056": {
"type": "text",
"fielddata": true
},
"6057": {
"type": "text",
"fielddata": true
},
"6058": {
"type": "text",
"fielddata": true
},
"6059": {
"type": "text",
"fielddata": true
},
"6060": {
"type": "text",
"fielddata": true
},
"6073": {
"type": "text",
"fielddata": true
},
"6074": {
"type": "text",
"fielddata": true
},
"6075": {
"type": "text",
"fielddata": true
},
"6076": {
"type": "text",
"fielddata": true
},
"6077": {
"type": "text",
"fielddata": true
},
"6078": {
"type": "text",
"fielddata": true
},
"6079": {
"type": "text",
"fielddata": true
},
"6080": {
"type": "text",
"fielddata": true
},
"6081": {
"type": "text",
"fielddata": true
},
"6082": {
"type": "text",
"fielddata": true
},
"6083": {
"type": "text",
"fielddata": true
},
"6084": {
"type": "text",
"fielddata": true
},
"-6c": {
"type": "text",
"fielddata": true
},
"110c": {
"type": "text",
"fielddata": true
},
"4899c": {
"type": "text",
"fielddata": true
},
"50c": {
"type": "text",
"fielddata": true
},
"2367c": {
"type": "text",
"fielddata": true
},
"4511": {
"type": "text",
"fielddata": true
}
}
}

{
"error": {
"root_cause": [
{
"type": "parsing_exception",
"reason": "Unknown key for a START_OBJECT in [properties].",
"line": 2,
"col": 16
}
],
"type": "parsing_exception",
"reason": "Unknown key for a START_OBJECT in [properties].",
"line": 2,
"col": 16
},
"status": 400
}