opensearch-php icon indicating copy to clipboard operation
opensearch-php copied to clipboard

[FEATURE] Ignore unmapped or missing fields in sort

Open Dgame opened this issue 2 years ago • 6 comments

Is your feature request related to a problem?

I would like to ignore unmapped or missing field, which is currently not possible (at least not according to the documentation)

What solution would you like?

Allow to ignore missing / unmapped fields

What alternatives have you considered?

There is currently no alternative

Do you have any additional context?

The documentation states that the sort works like this

  • $params['sort'] = (list) A comma-separated list of : pairs

But there is currently not way to express something like this:

"sort" : [
       { "rating": {"order" : "desc" , "ignore_unmapped" : true} },
       { "price": {"order" : "asc" , "missing" : "_last" , "ignore_unmapped" : true} }
]

missing and ignore_unmapped are not possible according to the documentation.

Dgame avatar Feb 16 '23 17:02 Dgame

Hey,

I am not sure if this is an SDK problem. For me it sounds like a general OpenSearch issue than an SDK here. Is that right?

shyim avatar Feb 16 '23 22:02 shyim

No, I guess the problem is that the sort parameter (like everything else except the body) is send in the query. If sort is present, it should be sent in the body too.

Dgame avatar Feb 17 '23 08:02 Dgame

Ahh okay, can you show a small example in PHP how you do it?

shyim avatar Feb 17 '23 08:02 shyim

I'm using the client with an array like in your tests. 🙂

$client = OpenSearch\ClientBuilder::create()->setHosts(["localhost:1"])->setRetries(0)->build();
$searchParams = [
      'index' => 'test',
      "sort" =>"rating:desc,price:asc",
      'body' => [
          'query' => [
              'match_all' => []
          ]
      ]
];
$client->search($searchParams);

But what I would like to do is:

$client = OpenSearch\ClientBuilder::create()->setHosts(["localhost:1"])->setRetries(0)->build();
$searchParams = [
      'index' => 'test',
      "sort" => [
             [ "rating" => ["order" => "desc" , "ignore_unmapped" => true] ],
             [ "price" => ["order" => "asc" , "missing" => "_last" , "ignore_unmapped" => true] ]
      ],
      'body' => [
          'query' => [
              'match_all' => []
          ]
      ]
];
$client->search($searchParams);

Dgame avatar Feb 18 '23 19:02 Dgame

@Dgame I think this is a fair request, let me see if OpenSearch supports these kinds of sort parameters and i'll update this issue.

harshavamsi avatar Mar 28 '23 16:03 harshavamsi

@Dgame You should be able to move the sort into body and then it should work as expected. The sort in the first level is the query string based sorting which does not support that

shyim avatar Apr 05 '23 17:04 shyim