解决match/range [match] malformed query, expected [END_OBJECT] but found [FIELD_NAME]

使用es查询数据的时候会遇到提示match/range [match] malformed query, expected [END_OBJECT] but found [FIELD_NAME]错误,这个时候你需要检查一下自己的query条件的大括号,这类问题基本是花括号的位置不正确引起的,例如

body = {"query": {
        "bool": {
            'must': [{"match_phrase": {'***': '***'}},
                     {'match_phrase': {'****': '****'}},
                     {'term': {'**': '**'}}]
        }},
        "from": **,
        "size":**
    }

是正确的,如果是这样就会报上述错误,下面是错误示范

body = {"query": {
        "bool": {
            'must': [{"match_phrase": {'***': '***'}},
                     {'match_phrase': {'****': '****'}},
                     {'term': {'**': '**'}}]
        },
        "from": **,
        "size": **
        }
    }

大家看出区别了吗,就是query的括号位置问题,因为在query里面没有from和size方法。

  • 4
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
分析一下下面这段代码 switch (session->version) { case NETCONFV10: //DBG("%s/%d", __func__,__LINE__); if (nc_session_read_until (session, NC_V10_END_MSG, 0, &text, &len) != 0) { goto malformed_msg_channels_unlock; } text[len - strlen (NC_V10_END_MSG)] = 0; WARN("Received message (session %s): %s", session->session_id, text); break; case NETCONFV11: DBG("%s/%d", __func__,__LINE__); do { if (nc_session_read_until (session, "\n#", 2, NULL, NULL) != 0) { if (total_len > 0) { free (text); } goto malformed_msg_channels_unlock; } if (nc_session_read_until (session, "\n", 0, &chunk, &len) != 0) { if (total_len > 0) { free (text); } goto malformed_msg_channels_unlock; } if (strcmp (chunk, "#\n") == 0) { /* 分块框架消息结束 */ free (chunk); break; } /* 将字符串转换为以下块的大小 */ chunk_length = strtoul (chunk, (char **) NULL, 10); if (chunk_length == 0) { ERROR("Invalid frame chunk size detected, fatal error."); goto malformed_msg_channels_unlock; } free (chunk); chunk = NULL; /* 现在我们有下一个块的大小,所以阅读块 */ if (nc_session_read_len (session, chunk_length, &chunk, &len) != 0) { if (total_len > 0) { free (text); } goto malformed_msg_channels_unlock; } /* * 如果需要,Realloc生成的文本缓冲区(现在总是需要) * 不要忘记计数终止空字节 * */ if (text_size < (total_len + len + 1)) { char *tmp = realloc (text, total_len + len + 1); if (tmp == NULL) { ERROR("Memory reallocation failed (%s:%d).", __FILE__, __LINE__); free(text); goto malformed_msg_channels_unlock; } text = tmp; text[total_len] = '\0'; text_size = total_len + len + 1; } memcpy(text + total_len, chunk, len); total_len += len; text[total_len] = '\0'; free (chunk); chunk = NULL;
06-08

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值