Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

the sort search is incorrect, I need help #2141

Closed
taobali32 opened this issue Jan 15, 2023 · 0 comments
Closed

the sort search is incorrect, I need help #2141

taobali32 opened this issue Jan 15, 2023 · 0 comments

Comments

@taobali32
Copy link

[code]

class TestListIndex extends BaseIndex
{
    public $NAME = '';

    public function __construct(Client $client = null)
    {
        parent::__construct($client);
        $this->NAME = $this->getName();
    }

    public function getName($index = 'test_list_index')
    {
        return $this->getIndexName($index);
    }

    protected $mapping = [
        '_source' => [
            'enabled' => true
        ],

        'properties' => [
            'id' => [
                'type' => self::TYPE_INTEGER,
            ],
            'user_id' => [
                'type' => self::TYPE_INTEGER,
            ],
            'type' => [
                'type' => self::TYPE_INTEGER,
            ],
            'num' => [
                'type' => self::TYPE_DOUBLE,
            ],
            'before' => [
                'type' => self::TYPE_DOUBLE,
            ],
            'after' => [
                'type' => self::TYPE_DOUBLE,
            ],
            'created_at' => [
                'type' => 'date',
                "format" => self::FORMAT_DATETIME
            ],
            'updated_at' => [
                'type' => 'date',
                "format" => self::FORMAT_DATETIME
            ]
        ]
    ];
}
    #[GetMapping]
    public function list2()
    {
        $size = (int)$this->request->input('size', 2);
        $page = (int)$this->request->input('page', 0);

        $builder = jtarApp()->get(ClientBuilderFactory::class)->create();

        $client = $builder->setHosts([env('ES_HOST')])->build();

        $params = [
            'index' => 'shiyan_test_list_index', 
            'body' => [
                'sort' => [
                    'id' => [
                        'order' => 'desc'
                    ]
                ],
                'from' => $page,
                'size' => $size,
                'query' => [
                    'bool' => [
                        'filter' => [
                            'term' => [
                                'type' => 0
                            ]
                        ]
                    ]
                ],
//                'query' => [
//                    'bool' => [
//                        'must' => [
//                            'match' => [
//                                'type' => 0
//                            ]
//                        ]
//                    ]
//                ],
//                'track_scores' => true,
//                'preference' => '_local',
            ],
        ];

        $result = $client->search($params);

        return $this->success('list', $result);
    }

course

page = 10, size = 0 or page = 1,size = 100 The sorting is correct

page = 1, size = 10 The sorting is not right

expect

  1. How to print dsl
  2. What's my question
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant