pepperoo
pepperoo

Reputation: 5

ElasticSearch returning expected value but got [START_ARRAY] Error

Currently experiencing this error in ES while trying to import data from a csv file:

{"error":{"root_cause":[{"type":"x_content_parse_exception","reason":"[1:428] [bool] failed to parse field [must]"}],"type":"x_content_parse_exception","reason":"[1:428] [bool] failed to parse field [filter]","caused_by":{"type":"x_content_parse_exception","reason":"[1:428] [bool] failed to parse field [must]","caused_by":{"type":"illegal_state_exception","reason":"expected value but got [START_ARRAY]"}}},"status":400} {"exception":"[object] (Exception(code: 0): {"error":{"root_cause":[{"type":"x_content_parse_exception","reason":"[1:428] [bool] failed to parse field [must]"}],"type":"x_content_parse_exception","reason":"[1:428] [bool] failed to parse field [filter]","caused_by":{"type":"x_content_parse_exception","reason":"[1:428] [bool] failed to parse field [must]","caused_by":{"type":"illegal_state_exception","reason":"expected value but got [START_ARRAY]"}}},"status":400}

I am still learning ES and need help in identifying which part of the query is causing the error? This is the logged query that was executed.

{
    "index": "collection_items",
    "body": {
        "_source": "*",
        "track_total_hits": true,
        "from": 0,
        "size": 24,
        "sort": {
            "updated_at": "desc"
        },
        "query": {
            "bool": {
                "should": [{
                    "match": {
                        "title.english": {
                            "query": "",
                            "boost": 15
                        }
                    }
                }],
                "must": [{
                    "query_string": {
                        "query": "*",
                        "fields": ["*"],
                        "default_operator": "and"
                    }
                }],
                "filter": {
                    "bool": {
                        "must_not": [{
                            "terms": {
                                "extra_data.user_type": ["group_leader", "person", "organization"]
                            }
                        }, {
                            "term": {
                                "type": "group_leader"
                            }
                        }, {
                            "term": {
                                "extra_data.disabled": "true"
                            }
                        }, {
                            "term": {
                                "extra_data_type": "favorites"
                            }
                        }],
                        "must": [
                            [{
                                "term": {
                                    "type": "resource"
                                }
                            }, {
                                "term": {
                                    "type_id": 335
                                }
                            }]
                        ]
                    }
                }
            }
        }
    }
}

Upvotes: 0

Views: 330

Answers (1)

Val
Val

Reputation: 217314

The problem is that you have one too many square brackets in this part:

                    "must": [
    remove this one --> [{
                            "term": {
                                "type": "resource"
                            }
                        }, {
                            "term": {
                                "type_id": 335
                            }
                        }]  <-- and this one
                    ]

Note, however, that your query can be simplified to the one below which is semantically equivalent:

{
  "index": "collection_items",
  "body": {
    "_source": "*",
    "track_total_hits": true,
    "from": 0,
    "size": 24,
    "sort": {
      "updated_at": "desc"
    },
    "query": {
      "bool": {
        "should": [
          {
            "match": {
              "title.english": {
                "query": "",
                "boost": 15
              }
            }
          }
        ],
        "must": [
          {
            "query_string": {
              "query": "*",
              "fields": [
                "*"
              ],
              "default_operator": "and"
            }
          }
        ],
        "must_not": [
          {
            "terms": {
              "extra_data.user_type": [
                "group_leader",
                "person",
                "organization"
              ]
            }
          },
          {
            "term": {
              "type": "group_leader"
            }
          },
          {
            "term": {
              "extra_data.disabled": "true"
            }
          },
          {
            "term": {
              "extra_data_type": "favorites"
            }
          }
        ],
        "filter": [
          {
            "term": {
              "type": "resource"
            }
          },
          {
            "term": {
              "type_id": 335
            }
          }
        ]
      }
    }
  }
}

Upvotes: 0

Related Questions