1
votes

Sending post request to elastic search following is the post data

{
    "query": {
            "has_child" : {
                "type" : "sometype",
                "score_mode" : "sum",
                "query" : {
                    "term" : {
                        "somefield" : "somevalue"
                    },
                    "function_score" : {
                        "script_score": {"script": "1"}
                    }
                },
                "inner_hits": {}
            }
        }
      }
    }

Getting response as malformed query

{
"error": {
    "root_cause": [
        {
            "type": "parsing_exception",
            "reason": "[term] malformed query, expected [END_OBJECT] but found [FIELD_NAME]",
            "line": 10,
            "col": 17
        }
    ],
    "type": "parsing_exception",
    "reason": "[term] malformed query, expected [END_OBJECT] but found [FIELD_NAME]",
    "line": 10,
    "col": 17
},
"status": 400

}

Read documentation from this link: https://www.elastic.co/guide/en/elasticsearch/reference/5.4/query-dsl-has-child-query.html

Elasticsearch version: 5.4

1
What happens if you remove the function_score query?Val
Its gives proper responseSagar Bakhtar

1 Answers

0
votes

You should make sure to wrap your term and function_score queries in a bool/filter query, like this:

{
  "query": {
    "has_child": {
      "type": "sometype",
      "score_mode": "sum",
      "query": {
        "bool": {
          "must": [
            {
              "term": {
                "somefield": "somevalue"
              }
            },
            {
              "function_score": {
                "script_score": {
                  "script": "1"
                }
              }
            }
          ]
        }
      },
      "inner_hits": {}
    }
  }
}