Giter VIP home page Giter VIP logo

Comments (3)

Mpdreamz avatar Mpdreamz commented on May 22, 2024

If ClassType1 and ClassType2 share a common base class or interface you could rewrite DeleteBySomething to

public void DeleteBySomething<T>(string test) where T : BaseClass //OR IMyInterface
{
    var client = new ElasticClient(elasticSettings);
    client.DeleteByQuery<T>(q => q.Term(f => f.TY, test));
}

If it really means find ANYTHING where f.TY equals string test

public void DeleteBySomething(string test)
{
    var client = new ElasticClient(elasticSettings);
    client.DeleteByQuery(q => q.Terms("TY", test)
   );
}

this will do a deletequery over _all indices and types. which is equivalant too:

public void DeleteBySomething(string test)
{
    var client = new ElasticClient(elasticSettings);
    client.DeleteByQuery(q => q
        .AllIndices()
        .AllTypes()
        .Terms("TY", test)
   );
}

You can limit this by explicitly specifying the indices and types

public void DeleteBySomething(string test)
{
    var client = new ElasticClient(elasticSettings);
    client.DeleteByQuery(q => q
        .Indices(new []{ "index1", "index2" })
        .Types(new[] { "type1", "type2" })
        .Terms("TY", test)
   );
}

or by being explicit on the types only:

public void DeleteBySomething(string test)
{
    var client = new ElasticClient(elasticSettings);
    client.DeleteByQuery(q => q
        .AllIndices()
        .Types(new[] { "type1", "type2" })
        .Terms("TY", test)
   );
}

or explicit indexes and all types which i'll omit because i'm sure you got the gist 2 examples ago :)

I quite like github issues over google groups personally since it feels like its more out in the open but thanks for offering!

from elasticsearch-net.

Mpdreamz avatar Mpdreamz commented on May 22, 2024

Also if you have a generic delete but you would like different default indexes for certain types you can do the following:

new ConnectionSettings(....)
    .SetDefaultIndex("index")
    .SetMaximumAsyncConnections(25)
    .MapTypeIndices(m => m
      .Add(typeof(Person), "persons-index") 
      .Add(typeof(Cars), "cars-index")
    );

That way you dont have to explicitly pass the exceptions into a different overload

from elasticsearch-net.

jptoto avatar jptoto commented on May 22, 2024

This is WONDERFUL. Thanks, man! I really appreciate the feedback. I'm just getting to know the NEST fluid interface a bit better.

from elasticsearch-net.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.