弹性搜索查询中的条件不起作用

时间:2017-12-22 12:01:56

标签: elasticsearch

我想搜索:当场地中存在客户ID>> blocked_for_customers然后我只想从搜索结果中删除ticket_type = 2的票证。我发布的ES查询未按预期工作。谁能帮助我找出我做错了什么?

这是我的ES文件:

{
  "took":44,
  "timed_out":false,
  "_shards":
  {
    "total":1,
    "successful":1,
    "failed":0
  },
  "hits":
  {
    "total":1,
    "max_score":1,
    "hits":
    [{
      "_index":"es_db",
      "_type":"event",
      "_id":"123",
      "_score":1,
      "_source":
      {
        "event_id":123,
        "name":"test event",
        "event_date":"2016-08-10T03:30:00",
        "status":1,
        "venue":
        [{
          "city":"dummy city",
          "name":"dummy name",
          "state":"dummy state",
          "venue_id":100,
          "blocked_for_customers":[1,2]
        }],
        "ticket_group":
        [{
          "ticket_type":1,
          "available":42,
          "price":100,
          "customer_id":1,
          "id":1
        },
        {
          "ticket_type":3,
          "available":5,
          "price":12.5,
          "id":2,
          "customer_id":1
        },
        {
          "ticket_type":2,
          "available":10,
          "id":3,
          "customer_id":1,
          "price":10
        }]
      }
    }]
  }
}

这是我的ES查询:

{
  "query":
  {
    "bool":
    {
      "must":
      [{
        "nested":
        {
          "path":"ticket_group",
          "score_mode":"max",
          "inner_hits":
          {
            "from":0,
            "size":10000
          },
          "query":
          {
            "bool":
            {
              "must":
              [{
                "bool":
                {
                  "minimum_should_match":1,
                  "should":
                  [{
                    "bool":
                    {
                      "must":
                      [{
                        "match":
                        {
                          "venue.blocked_for_customers":1
                        }
                      },
                      {
                        "terms":
                        {
                          "ticket_group.ticket_type":[1,3]
                        }
                      }]
                    }
                  },
                  {
                    "bool":
                    {
                      "must":
                      [{
                        "bool":
                        {
                          "must_not":
                          [{
                            "match":
                            {
                              "venue.blocked_for_customers":1
                            }
                          }]
                        }
                      },
                      {
                        "bool":
                        {
                          "must":
                          [{
                            "terms":
                            {
                              "ticket_group.ticket_type":[1,3,2]
                            }
                          }]
                        }
                      }]
                    }
                  }]
                }
              }]
            }
          }
        }
      },
      {
        "match":
        {
          "status":1
        }
      }]
    } 
  },
  "size":10,
  "from":0,
  "sort":
  {
    "event_date":
    {
      "order":"asc"
    }
  }
}

映射:

{"mappings": {
      "event":{
         "properties":{
            "event_date":{
               "type":"date",
               "format":"strict_date_optional_time||epoch_millis"
            },
            "event_id":{
               "type":"integer",
               "index":"not_analyzed"
            },
            "name":{
               "type":"string",
               "analyzer":"autocomplete",
               "search_analyzer":"standard",
               "fields":{
                  "raw":{
                     "type":"string",
                     "index":"not_analyzed"
                  }
               }
            },
            "status":{
               "type":"integer"
            },
            "ticket_group":{
               "type":"nested",
               "properties":{
                  "price":{
                     "type":"double",
                     "index":"not_analyzed"
                  },
                  "ticket_type":{
                     "type":"integer"
                  },
                  "available":{
                     "type":"integer"
                  },
                  "customer_id":{
                     "type":"string"
                  },
                  "id":{
                     "type":"integer",
                     "index":"not_analyzed"
                  }
               }
            },
            "venue":{
               "type":"nested",
               "properties":{
                  "blocked_for_customers" :{
                     "type":"string"
                  },
                  "name":{
                     "type":"string",
                     "analyzer":"autocomplete",
                     "search_analyzer":"standard"
                  },
                  "venue_id":{
                     "type":"string",
                     "index":"not_analyzed"
                  },
                  "city":{
                     "type":"string"
                  },
                  "state":{
                     "type":"string"
                  }
               }
            }
         }
      }
   }
}

0 个答案:

没有答案