2016-07-22 19 views
0

ich Nest bin mit 1.7 und ich brauche diese Abfrage zu schreiben:, wie man schreibt existsQuery im Nest 1.7

GET _search 
{ 
    "from": 0, 
    "size": 3, 
    "query": { 
     "bool": { 
     "must": [ 
      { 
       "constant_score": { 
        "filter": { 
        "bool": { 
         "must": [ 
          { 
           "bool": { 
           "must": [ 
            { 
             "exists": { 
              "field": "Collaborateurs" 
             } 
            }, 
            { 
             "exists": { 
              "field": "Collaborateurs.Nom" 
             } 
            }, 
            { 
             "exists": { 
              "field": "Collaborateurs.Fonction" 
             } 
            }, 
            { 
             "exists": { 
              "field": "Collaborateurs.TagVisuel" 
             } 
            }, 
            { 
             "exists": { 
              "field": "siAnnuaire" 
             } 
            }, 
            { 
             "term": { 
              "siAnnuaire": { 
              "value": true 
              } 
             } 
            }, 
            { 
             "exists": { 
              "field": "TagPhoto" 
             } 
            }, 
            { 
             "range": { 
              "NbAnnonce": { 
              "gt": 0 
              } 
             } 
            }, 
            { 
             "geo_distance": { 
              "distance": "10.0km", 
              "AgenceLocation": { 
              "lat": 48.8523513700019, 
              "lon": 2.35127712591128 
              } 
             } 
            } 
           ] 
           } 
          } 
         ] 
        } 
        } 
       } 
      }, 
      { 
       "function_score": { 
        "functions": [ 
        { 
         "random_score": { 
          "seed": 69937385 
         } 
        } 
        ] 
       } 
      } 
     ] 
     } 
    } 
} 
+0

Haben Sie eine spezifischere Frage, mit der wir Ihnen vielleicht helfen können? – Ares

+0

Ich finde nicht, wie man in Nest 1.7 existsQuery schreibt, ich kann diesen Typ in Nest 2.XX finden, aber nicht in der Version 2 – user1428798

+0

Anreise dahin, aber immer noch zu breit. Wir brauchen etwas, das ziemlich eng ist, sonst reicht die Frage nur aus "schreibe meinen Code", was allgemein verpönt ist. – Ares

Antwort

1

die fließend API verwenden, befolgen Sie die Methodenaufrufe ziemlich die Struktur der Abfrage DSL json

var response = client.Search<Document>(x => x 
    .From(0) 
    .Size(3) 
    .Query(q => q 
     .Bool(b => b 
      .Must(m => m 
       .ConstantScore(cs => cs 
        .Filter(csf => csf 
         .Bool(cb => cb 
          .Must(
           cm => cm.Exists(p => p.Collaborateurs), 
           cm => cm.Exists(p => p.Collaborateurs.Nom), 
           cm => cm.Exists(p => p.Collaborateurs.Fonction) 
           // etc, etc for the other queries 
          ) 
         ) 
        ) 
       ), m => m 
       .FunctionScore(fs => fs 
        .Functions(fu => fu 
         .RandomScore(69937385) 
        ) 
       ) 
      ) 
     ) 
    ) 
); 

die

{ 
    "from": 0, 
    "size": 3, 
    "query": { 
    "bool": { 
     "must": [ 
     { 
      "constant_score": { 
      "filter": { 
       "bool": { 
       "must": [ 
        { 
        "exists": { 
         "field": "collaborateurs" 
        } 
        }, 
        { 
        "exists": { 
         "field": "collaborateurs.nom" 
        } 
        }, 
        { 
        "exists": { 
         "field": "collaborateurs.fonction" 
        } 
        } 
       ] 
       } 
      } 
      } 
     }, 
     { 
      "function_score": { 
      "functions": [ 
       { 
       "random_score": { 
        "seed": 69937385 
       } 
       } 
      ] 
      } 
     } 
     ] 
    } 
    } 
} 

Feldnamen liefert wurden durch Standardkamel verrohrten, aber Sie können thi ändern s Verhalten mit .SetDefaultPropertyNameInferrer(Func<string, string>) auf ConnectionSettings.