ElasticSearch 6.x:使语法更短

时间:2018-04-02 07:38:31

标签: elasticsearch elasticsearch-6

我想让make来搜索这句话。

title: Change my room!
description: I change my desk and chair. These make my room more beautiful! 

我想在每个部分,标题,说明上搜索用户查询。 我在服务器端进行查询语法。例如,当用户发送查询时,

query: change desk chair

然后服务器像这样做

{
  "query": {
    "bool": {
      "should": [
        {
          "bool": {
            "must": [
              {
                "match_phrase": {
                  "description": "change"
                }
              },
              {
                "match_phrase": {
                  "description": "desk"
                }
              },
              {
                "match_phrase": {
                  "description": "chair"
                }
              }
            ]
          }
        },
        {
          "bool": {
            "must": [
              {
                "match_phrase": {
                  "title": "change"
                }
              },
              {
                "match_phrase": {
                  "title": "desk"
                }
              },
              {
                "match_phrase": {
                  "title": "chair"
                }
              }
            ]
          }    
        }
      ]   
    }
  }
}

我可以缩短此查询语法吗?

1 个答案:

答案 0 :(得分:-1)

您可以使用query_string或match query来执行此操作。

示例:

curl -XPOST 'localhost:9200/_search?pretty' -d '
{
      "query": { "match": { "_all": "Change my room" } }
}'

curl -XPOST 'localhost:9200/_search?pretty' -d '{
      "query": { "query_string": { "query": "Change my room" } }
}'