弹性搜索转换php

时间:2017-11-27 10:11:41

标签: mysql elasticsearch

我想将MySQL查询转换为php中的弹性搜索

SELECT id,username,full_name 
FROM users 
WHERE id<>4 AND (username LIKE %john% OR full_name LIKE %full_name%) 
LIMIT 50 OFFSET 0

请教育

1 个答案:

答案 0 :(得分:1)

它是这样的:

GET /users/_search?pretty=true
{
  "size": 50,
  "query": {
    "bool": {
      "should": [
        {
          "terms": {
            "username": "john"
          }
        },
        {
          "terms": {
            "full_name": "full_name"
          }
        }
      ],
      "must_not": [
        {
          "term": {
            "id": "4"
          }
        }
      ]
    }
 }