简体   繁体   中英

Elastic Search Nest C# Syntax Error: using wildcard and multimatch within one query

I have a query where I want to have two clauses: one for .MultiMatch and one for .Wildcard . The wildcard is independent of the multimatch.

I can get them both working separately, but not together. The current error message in Visual Studio has the Wildcard word underlined and says the following:

Querycontainer does not contain a definition for 'Wildcard'...

Here is the code I am trying to implement. I have tried putting .Wildcard and .MultiMatch in separate .Should pieces but to no avail.

.Query(q => q
  .Bool(b => b
    .Should(m => m                             
      .MultiMatch(ma => ma
        .Fields(f => f.Field("_id")
          .Field("elements.location.city")
          .Field("ticket_number")
          )
          .Query(query)
        )
        .Wildcard(c => c
          .Field("name").Value(query.ToLower() + "*")
        )
      )
    )
  )

The query you see on line 8 is passed into this function as an argument.

As stated above, line 10 is the issue at hand as the Query container does not know what to do with Wildcard.

Any and all input is appreciated.

It depends what boolean condition you want between the MultiMatch and Wildcard queries?

For example here, I am looking for records which satisfy both MultiMatch AND WildCard queries:

.Query(q => q
    .Bool(b => b
        .Must(m => m
            .MultiMatch(mm => mm
                .Fields(f => f.Field("FieldName"))
                .Query("MyKeyword")

            ), wc => wc
            .Wildcard(c => c
                .Field("FieldName")
                .Value("*Something*")
            )
        )
    )
));

If you want to OR them, use Should instead of Must : see Bool Query Usage

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM