0

我在 ElasticSearch 中有以下映射:

{
  "xenforo" : {
    "post" : {
      "_source" : {
        "enabled" : false
      },
      "properties" : {
        "date" : {
          "type" : "long",
          "store" : "yes"
        },
        "discussion_id" : {
          "type" : "long",
          "store" : "yes"
        },
        "message" : {
          "type" : "string"
        },
        "node" : {
          "type" : "long"
        },
        "thread" : {
          "type" : "long"
        },
        "title" : {
          "type" : "string"
        },
        "user" : {
          "type" : "long",
          "store" : "yes"
        }
      }
    },

我想在消息字段中搜索单词 test 但将其限制为节点 id 5。我将如何修改此 DSL 搜索?

$data_string = '{
"from" : 0, "size" : 100,
"sort" : [
    { "date" : {"order" : "desc"} }
],
"query": {
        "match" : {
            "message" : {
                "query" : "test"
            }
        }
    }
}';

感谢您的协助。

4

1 回答 1

1

您可以使用过滤查询:

{
  "from": 0,
  "size": 100,
  "sort": [{
    "date": {
      "order": "desc"
    }
  }],
  "query": {
    "filtered": {
      "query": {
        "match": {
          "message": {
            "query": "test"
          }
        }
      },
      "filter": {
        "term": {
          "node": 5
        }
      }
    }
  }
}
于 2013-04-14T00:41:41.553 回答