2017-09-14 13 views
1

categories,postsの2つのインデックスがあります。インデックスにインデックスがある場合にのみインデックスを使用するフィルタ

カテゴリ

投稿

  • publish_at
  • publish_until

私はpostsインデックスにpublish_atpublish_untilにフィルター付きの両方のインデックスにクエリを実行します。

http://localhost:9200/categories,posts/_search

{ 
     "query": { 
      "bool": { 
       "must": { 
        "multi_match": { 
         "query": "keyword", 
         "fields": [ 
          "name^3", 
          "body" 
         ] 
        } 
      }, 
      "filter": [{ 
       "bool": { 
        "must": [ 
         { 
          "range": { 
           "publish_at": { 
            "lte" : "now" 
           } 
          } 
         }, 
         { 
          "range": { 
           "publish_until": { 
            "gt" : "now" 
           } 
          } 
         } 
        ] 
       } 
      }] 
     } 
    } 
} 

このクエリは結果だけとして私をposts与えます。私はまた、私の結果にcategoriesが欲しいです。

publish_atpublish_untilフィールドのインデックスのみに日付範囲フィルタを適用し、他のインデックスの日付範囲フィルタをスキップするにはどうすればよいですか?

答えて

1

[OK]をboolをいじるの日の後、私はそれが働いてしまった:

{ 
    "query": { 
     "bool" : { 
      "must" : [ 
       { 
        "multi_match": { 
         "query": "keyword", 
         "fields": [ 
          "name^3", 
          "body" 
         ] 
        } 
       }, 
       { 
        "bool": { 
         "should": [ 
          { 
           "bool": { 
            "must": [ 
             { 
              "range": { 
               "publish_at": { 
                "lte" : "now" 
               } 
              } 
             }, 
             { 
              "range": { 
               "publish_until": { 
                "gt" : "now" 
               } 
              } 
             } 
            ] 
           } 
          }, 
          { 
           "bool": { 
            "must_not": [ 
             { 
              "exists": { 
               "field": "publish_at" 
              } 
             }, 
             { 
              "exists": { 
               "field": "publish_until" 
              } 
             } 
            ] 
           } 
          } 
         ] 
        } 
       } 
      ] 
     } 
    } 
} 
関連する問題