开发者社区> 问答> 正文

使用通配符的ElasticSearch LIKE查询

我正在尝试为JSON以下实现类似的功能。

SELECT * FROM TABLE_NAME WHERE ORGID =“ BACKENDORG” AND TYPE =“ AUDIT” AND 
(sessionId LIKE'%16ECA064B298356B%'或loginUserId LIKE'%16ECA064B298356B%'或txnId LIKE'%16ECA064B298356B%');

{
  "sessionId": "16ECA064B298356B",
  "message": "2019-12-03T05:29:13.217Z [http-nio-8080-exec-4] INFO  http-nio-8080-exec-4 QueryController backendorg 16CFAFCCFB14D9A3 16ECA064B298356B 16ECA3A4EFA026BF 
  "type": "audit",
  "orgId": "backendorg",
  "loginUserId": "16CFAFCCFB14D9A3",
  "txnId": "16ECA3A4EFA026BF"
 }

试图使用BoolQueryBuilder编写一个LIKE查询,这是我的查询

{
  "query": {
    "bool": {
      "must": [
        {
          "term": {
            "orgId": {
              "value": "backendorg",
              "boost": 1
            }
          }
        },
        {
          "term": {
            "type": {
              "value": "audit",
              "boost": 1
            }
          }
        },
        {
          "bool": {
            "should": [
              {
                "wildcard": {
                  "sessionId": {
                    "wildcard": "16ECA064B298356B",
                    "boost": 1
                  }
                }
              },
              {
                "wildcard": {
                  "loginUserId": {
                    "wildcard": "16ECA064B298356B",
                    "boost": 1
                  }
                }
              },
              {
                "wildcard": {
                  "txnId": {
                    "wildcard": "16ECA064B298356B",
                    "boost": 1
                  }
                }
              }
            ],
            "adjust_pure_negative": true,
            "minimum_should_match": "1",
            "boost": 1
          }
        }
      ],
      "adjust_pure_negative": true,
      "boost": 1
    }
  }
}

上面的查询应返回上面的JSON结果,但显示为零。如果有人指出这个问题,将会很有帮助。

展开
收起
垚tutu 2019-12-04 16:33:34 880 0
0 条回答
写回答
取消 提交回答
问答排行榜
最热
最新

相关电子书

更多
阿里云Elasticsearch体系架构与特性解析 立即下载
开源与云:Elasticsearch应用剖析 立即下载
《Elasticsearch全观测解决方案》 立即下载