0

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
                                }
                            }]
                        ]
                    }
                }
            }
        }
    }
}

1 Answer 1

0

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
            }
          }
        ]
      }
    }
  }
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.