2016-04-28 7 views
1

私はelasticsearchクエリを持っている:Elasticsearch "スパンと"

のような句何か含めるで、私が持っている必要があり
"query": { 
    "bool": { 
     "minimum_should_match": 1, 
     "should": { 
      "span_not": { 
       "exclude": { 
        "span_or": { 
         "clauses": [{ 
          "span_near": { 
           ... 
          }, 
          "span_near": { 
           ... 
          } 
         }] 
        } 
       }... 

:「私が持っていることを、私は意味

"span_or": { 
clauses: [ 
{ 
    "span_near": {...} 
} 
, 
{ 
    "span_and": { 
     "clases": [ 
     { 
      "span_near": {...} 
     } 
     , 
     { 
      "span_near": {...} 
     } 
     , 
     ... 
     ] 
    } 
} 
] 

}

をまたは「クエリ:

(span_near or span_near or span_near or ...) 

そして私はgにしたいet "and" query:

(span_near or (span_near and span_near) or ...) 

どうすればいいですか?タグ「span_and」はありません。代わりにあなたのタグは何ですか?

アップデート1

私はこれ試してみました:

"span_or": { 
          clauses: [ 
          { 
           "span_multi": { 
            "match": { 
             "regexp": { 
              "message": "путин.*" 
             } 
            } 
           } 
          } 
          , 
          { 
           "span_multi": { 
            "match": { 
             "bool": { 
              "must": [ 
               { 
                "term" : { "message" : "test" } 
               }, 
               { 
                "term" : { "message" : "rrr" } 
               } 
              ] 
             } 
            } 
           } 
          } 
          ] 
         } 

をしかし、私はエラーを持っている:

spanMultiTerm [match] must be of type multi term query

+0

あなたはbool'クエリ 'と試みたと' must'セクションの句として各 'span_near'を指定することがありますか? –

+0

私は更新1で答えました – maxx

答えて

0

なり、通常のboolクエリはあなたの問題を解決しますか?

{ 
    "query": { 
     "bool": { 
      "must_not": { 
       "bool": { 
        "should": [ 
         { 
          "regexp":{ 
           "message": "путин.*" 
          } 
         }, 
         { 
          "bool": { 
           "must": [ 
            { 
             "span_near": {...} 
            }, 
            { 
             "span_near": {...} 
            } 
           ] 
          } 
         } 
        ] 
       } 
      } 
     } 
    } 
} 
+0

"span_not"や "include"/"exclude"とまったく同じですか? – maxx

+0

正確ではありません。 'Span_not'は単純なブール条件よりも少し複雑です。包含スパンと除​​外スパンが特定の方法で重なっているかどうかが考慮されます。しかし、大したことではないユースケースのためにおそらく。 'Span_not'の詳細はこちら:https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-span-not-query.html – slawek

0

私は、次のアイデアを使用してはhereが見つかりました:

In certain situations, it can be convenient to have a SpanAndQuery . You can easily simulate this using a SpanNearQuery with a distance of Integer.MAX_VALUE.

"span_or": { 
    clauses: [ 
    { 
     "span_multi": { 
      "match": { 
       "regexp": { 
        "message": "путин.*" 
       } 
      } 
     } 
    } 
    , 
    { 
     "span_near": { 
      "clauses": [ 
       { 
        "span_term" : { "message" : "test" } 
       }, 
       { 
        "span_term" : { "message" : "rrr" } 
       } 
      ], 
      "slop": 2147483647, 
      "in_order": false 
     } 
    } 
    ] 
} 
関連する問題