前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >cssjshtml vue直接调用elasticsearch接口

cssjshtml vue直接调用elasticsearch接口

作者头像
葫芦
修改2019-10-26 16:25:49
1.7K0
修改2019-10-26 16:25:49
举报
文章被收录于专栏:葫芦葫芦

欢迎访问主页: https://www.bthlt.com/


es query查询

es同一字段多条件合并查询:

代码语言:javascript
复制
{
    "query":{
        "bool":{
            "must":{
                "bool":{
                    "must":[
                        {
                            "match_phrase":{
                                "message":"request"
                            }
                        },
                        {
                            "match_phrase":{
                                "message":this.openid
                            }
                        }
                    ]
                }
            }
        }
    },
    "_source":[
        "message",
        "@timestamp"
    ]
}

axios调用es接口认证解决方法

通过headers中设置:Authorization  来通过验证,Authorization通过正常登陆页面后在headers中获取。此方法牺牲了安全。

JSON.parse(jsonstr):用来解析json字符串,转为json对象。 json.hasOwnProperty(key):用来判断json中是否有此key。

代码语言:javascript
复制
axios.post(es_url, es_data,
                    {

                        headers: {
                            'Authorization': 'Basic ********',
                            'Content-Type': 'application/json'
                        }
                    }
                ).then((res) => {

                    res.data.hits.hits.forEach(function (item, index) {
                        let message = JSON.parse(item['_source']['message'].substring(12))
                        console.log(message)
                        let path = ''
                        let globalticket = ''
                        let body = ''
                        if (message.hasOwnProperty("path")) {
                            path = message['path']

                        }
                        if (message.hasOwnProperty('url')) {
                            path = message['url']

                        }
                        if (message.hasOwnProperty('headers')) {
                            globalticket = '*******=' + message['headers']['globalticket']

                        }
                        if (message.hasOwnProperty('body')) {
                            body = JSON.stringify(message['body'])

                        }

                        messsages.push({
                            "path": path,
                            "globalticket": globalticket,
                            "body": body,

                            "timestamp": item['_source']['@timestamp']
                        })
                    })

                })

表格设置:

表格内内嵌跳转链接:

<template slot-scope="scope"> <a :href="'http://'+scope.row.globalticket" target="_blank" class="buttonText">{{scope.row.globalticket.split('=')[1]}}</a> </template>

超长隐藏:

<el-table-column

                        prop="body"

                        label="body" :show-overflow-tooltip="true">

代码语言:javascript
复制
            <el-table
                    :data="tableData"
                    style="width: 100%">
                <el-table-column
                        width="240"
                        sortable
                        prop="timestamp"
                        label="timestamp">
                </el-table-column>
                <el-table-column
                        width="500"
                        prop="path"
                        label="path">
                </el-table-column>
                <el-table-column
                        width="500"

                        prop="globalticket"
                        label="globalticket" :show-overflow-tooltip="true">
                    <template slot-scope="scope">
                        <a :href="'http://'+scope.row.globalticket"
                           target="_blank"
                           class="buttonText">{{scope.row.globalticket.split('=')[1]}}</a>
                    </template>

                </el-table-column>
                <el-table-column
                        prop="body"
                        label="body" :show-overflow-tooltip="true">
                </el-table-column>
            </el-table>
本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2019/10/24 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • es query查询
  • axios调用es接口认证解决方法
  • 表格设置:
    • <template slot-scope="scope"> <a :href="'http://'+scope.row.globalticket" target="_blank" class="buttonText">{{scope.row.globalticket.split('=')[1]}}</a> </template>
    领券
    问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档