1

I want to create NEST equivalent for this json query:

{
    "query": {
        "more_like_this" : {
            "fields" : ["storages.items"],
            "like" :  ["a","b"],
            "min_term_freq": 1,
            "min_doc_freq": 1
        }
    }
}

My model is:

public class Data
{
    public string Name { get; set; }

    public InnerStorage[] Storages { get; set; }

}

public class InnerStorage
{
    public string[] Items { get; set; }
}

And problem is that I couldn't find way to pass array of strings to MoreLikeThis parameters.

LikeDescriptor contains only

Text(string likeText)

and

Document(Func<LikeDocumentDescriptor<T>, ILikeDocument> selector)

And only request I can create is something like

 var data =
      client.Search<Data>(
        x =>
          x.Query(
            q =>
              q.MoreLikeThis(
                s =>
                  s.Fields(Field.Create("storages.items"))
                    .Like(sel => sel.Document(d => d.Document(
                      new Data(){Storages =new[]{new InnerStorage(){Items = new[] {"a", "b"}}}}
                                                       ))))));

It contains full Data document (but I want to pass only array of strings (Items)) and creates wrong request for like:

"like": [{
                "_index": null,
                "_type": "data",
                "doc": {
                    "storages": [{
                        "items": ["a", "b"]
                    }]
                }
            }]
Vladimir
  • 2,082
  • 1
  • 13
  • 27

1 Answers1

2

You can add more terms into like part of the query by calling fluent method Text for each term, just like in this example:

var searchResponse = client.Search<Document>(s => s
    .Query(q => q
        .MoreLikeThis(mlt => mlt
            .Fields(f => f.Field(ff => ff.Title))
            .Like(l => l.Text("a").Text("b")))));

Hope it helps.

Rob
  • 9,664
  • 3
  • 41
  • 43