SDKits / ExamineX

Issue tracker for ExamineX
https://examinex.online
5 stars 0 forks source link

ExamineX for Elasticsearch does not parse Lucene query correctly #113

Open raimondkempees-arc opened 8 hours ago

raimondkempees-arc commented 8 hours ago

Describe the bug I'm trying out ExamineX for Elasticsearch and find that the query posted to Elasticsearch is incorrect in the following cases:

Note I'm probably doing something stupid.

When I do this:


           if (_examineManager.TryGetIndex(Constants.UmbracoIndexes.ExternalIndexName, out var examineIndex))
        {
            var searcher = examineIndex.Searcher;
            var query = searcher.CreateQuery().Field("content", q);

            var results = query.Execute().Select(r => r.AllValues);

            _logger.LogDebug("We have {x} results.", results.Count());
        }

The output is: "type" : "parse_exception", "reason" : "request body is required", "stack_trace" : "org.elasticsearch.ElasticsearchParseException: request body is required\n\tat org.elasticsearch.server@8.6.1/

When I do this:


 if (_examineManager.TryGetIndex(Constants.UmbracoIndexes.ExternalIndexName, out var examineIndex))
        {
            var searcher = examineIndex.Searcher;
            var query = searcher.CreateQuery("content", BooleanOperation.And).Field("content", q);

            var results = query.Execute().Select(r => r.AllValues);

            _logger.LogDebug("We have {x} results.", results.Count());
        }

I get

"stack_trace" : "org.apache.lucene.queryparser.classic.ParseException: Cannot parse '+x__IndexType:content +':

When I do a plain

searcher.Search("test")

I get back one result.

License ID No license yet

To Reproduce See above.

Expected behavior I expect to get search results back.

Versions

Shazwazza commented 5 hours ago

Hi @raimondkempees-arc,

A few questions:

When testing locally against the elastic 8.12.1 container using the following code, I get the following results:

using (Setup.Index.ProcessNonAsync())
{
    Setup.Index.IndexItems(new[] {
        ValueSet.FromObject(NewId(), "content",
            new { content = "test" }),
        ValueSet.FromObject(NewId(), "content",
            new { content = "asdf" }),
    });
}

var searcher = GetDelayedSearcher();
var query = searcher.CreateQuery("content", BooleanOperation.And).Field("content", "test");

var result = query.Execute();
var results = result.Select(r => r.AllValues);

Console.WriteLine("We have {0} results.", result.TotalItemCount);
Console.WriteLine("We have {0} values.", results.Count());

results:

  Standard Output: 
dbug: ExamineX.ElasticSearch.ElasticSearchIndex[0]
      Creating new index (elastictest)
dbug: ExamineX.ElasticSearch.ElasticSearchIndex[0]
      Ensuring fields
dbug: ExamineX.ElasticSearch.ElasticSearchIndex[0]
      Ensuring fields, missing 1
We have 1 results.
We have 1 values.