Home > Mobile >  Error in Term Parsing in Elastic search question
Error in Term Parsing in Elastic search question

Time:02-24

I have the following query:

{
  "aggs": {
    "groupby": {
      "terms": {
        "field": "AMAZING LONG NAME THAT MAKES NO SENSE",
        "missing": "",
        "order": [
          {
            "_term": "asc"
          }
        ],
        "size": 10038
      }
    }
  },
  "query": {
    "bool": {
      "filter": [
        {
          "bool": {
            "must": [
              {
                "term": {
                  "match": {
                    "AMAZING LONG NAME THAT MAKES NO SENSE": "Term1"
                  }
                }
              }
            ]
          }
        }
      ]
    }
  },
  "size": 10
}

And it raises a parsing_exception

{
    "error": {
        "root_cause": [
            {
                "type": "parsing_exception",
                "reason": "[term] query does not support [AMAZING LONG NAME THAT MAKES NO SENSE]",
                "line": 1,
                "col": 235
            }
        ],
        "type": "x_content_parse_exception",
        "reason": "[1:235] [bool] failed to parse field [filter]",
        "caused_by": {
            "type": "x_content_parse_exception",
            "reason": "[1:235] [bool] failed to parse field [must]",
            "caused_by": {
                "type": "parsing_exception",
                "reason": "[term] query does not support [AMAZING LONG NAME THAT MAKES NO SENSE]",
                "line": 1,
                "col": 235
            }
        }
    },
    "status": 400
}

My question is should it be the field name that is to be entered in match?

CodePudding user response:

The Term query syntax can be corrected as belwo :

POST demoindex/_search
  {
  "aggs": {
    "groupby": {
      "terms": {
        "field": "AMAZING LONG NAME THAT MAKES NO SENSE",
        "missing": "",
        "order": [
          {
            "_term": "asc"
          }
        ],
        "size": 10038
      }
    }
  },
  "query": {
    "bool": {
      "filter": [
        {
          "bool": {
            "must": [
              {
                "term": {
                  "AMAZING LONG NAME THAT MAKES NO SENSE": {
                    "value": "Term1"
                  }
                }
              }
            ]
          }
        }
      ]
    }
  },
  "size": 10
}

Term query syntax is as belwo:

query -> term -> fieldname(to perform exact match on)--> value

  • Related