Reputation: 189
I am trying to get my elasticsearh query to work, but I get this error:
org.elasticsearch.common.ParsingException: [exists] unknown token [START_ARRAY] after [field]
The query is supposed to get all documents that have dates in either date.old or date.new between the two years(1500,1550), and also include documents that have undefined values for those fields.
This is my query:
{
"query":{
"bool":{
"should":[
{
"range":{
"date.old":{
"gte":1500,
"lte":1550
}
}
},
{
"range":{
"date.new":{
"gte":1500,
"lte":1550
}
}
},
{
"bool":{
"must_not":{
"exists":{
"field":"date.new"
}
}
}
},
{
"bool":{
"must_not":{
"exists":{
"field":"date.old"
}
}
}
}
]
}
}
}
Do anyone see the problem here? Thanks!
Upvotes: 1
Views: 2710
Reputation: 16192
Hitting the same search query as given in the question above gives no parsing error.
Adding a working example with index mapping, index data, and search result
Index Mapping:
{
"mappings": {
"properties": {
"date": {
"properties": {
"old": {
"type": "long"
},
"new": {
"type": "long"
}
}
}
}
}
}
Index Data:
{
"data": {
"new": 1501,
"old": 10
}
}
{
"title": "elasticsearch"
}
Search Result:
"hits": [
{
"_index": "65112793",
"_type": "_doc",
"_id": "1",
"_score": 1.0,
"_source": {
"date": {
"new": 1501,
"old": 10
}
}
},
{
"_index": "65112793",
"_type": "_doc",
"_id": "2",
"_score": 0.0,
"_source": {
"title": "elasticsearch"
}
}
]
EDIT 1:
Based on the comment below:
Search Query:
{
"query": {
"bool": {
"should": [
{
"range": {
"date.old": {
"gte": 1500,
"lte": 1550
}
}
},
{
"range": {
"date.new": {
"gte": 1500,
"lte": 1550
}
}
}
],
"must": [
{
"bool": {
"must_not": {
"exists": {
"field": "date.new"
}
}
}
},
{
"bool": {
"must_not": {
"exists": {
"field": "date.old"
}
}
}
}
]
}
}
}
Upvotes: 1