'Elasticsearch NEST API - querying the right index

Using the C# NEST API on Elasticsearch:

var searchResults = client.Search<Product>(s => s
                .Index(Constants.ElasticSearchIndex)
                .Query(q => q
                    .Raw(jsonRequest)
                )
            );

The query is supposed to run on the /sc_all/ index, but it runs on /sc_all/product/ index (which doesn't exist - /product/ seems to be added because of the Search since T = product).

If I do like this, /product/ is replaced with the value of the constant, i.e. /sc_all/product/ => /sc_all/constant_value/:

var searchResults = client.Search<Product>(s => s
                .Index(Constants.ElasticSearchIndex)
                .Type(Constants.ElasticSearchType)
                .Query(q => q
                    .Raw(jsonRequest)
                )
            );

What should I do if I just want to query /sc_all/ and nothing else?

Thanks!


Json request:

"{\"filtered\": {\"query\": {\"match_all\": { }},\"filter\": {\"nested\" : {\"path\" : \"products\",\"filter\": {\"nested\" : {\"path\" : \"products.da\",\"filter\": { \"bool\": { \"must\": [{\"query\": {\"query_string\": {\"default_field\" : \"products.da.content\", \"query\" : \"kildemoes\"}}}]}}}}}}}}, \"from\": 0, \"size\": 100"



Solution 1:[1]

You were using an outdated version client, like 5.x. I came across the same problem too using 5.x. The second subpath is the document type, which is the _type name of your document and is docs by default. So, the solution I use is to add [ElasticsearchType(Name = "docs")] at the top of my POCO class and the search path will is something like /{indexname}/docs/_search, and it's fine.

Solution 2:[2]

First of all, it would be good if you showed some code. Second, I'm hoping you've already looked at this goap demo

This should answer your question. Preconditions are to be met before an action is presented. So for example, if you require the AI to eat the muchroom m before picking up a sword, I would do something like this:

Eat mushroom action: effect: "mushroomEaten" == true

Pick up sword action: precondition: if "mushroomEaten" == true

then

effect: "goPickUpSword"

I have to generalize since your question is also general with no specific code example given. Look at the link provided and you will understand how actions can be chained together to accomplish a goal.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 UndeadBob
Solution 2 Lionboy1