Giter Site home page Giter Site logo

Facets about elasticsearch-php HOT 4 CLOSED

elastic avatar elastic commented on May 17, 2024
Facets

from elasticsearch-php.

Comments (4)

hellovic avatar hellovic commented on May 17, 2024

Sorry I think I know where the problem is.

Instead of using json_decode() for transferring JSON to php array, I just use the JSON string as the ['body']

$sESSearch = '{ query...facets...}';
$aESSearchParam['index'] = $sESIndex;
$aESSearchParam['type'] = $sESType;
$aESSearchParam['body'] =$sESSearch;
$aReturnArray = $oESClient->search($aESSearchParam);

It throws no error and gives ['hits'] records so I thought it was ok to accept the JSON string directly.

After doubled checked ['hits'], and it is not correct, it actually gives all records, that means the search ['body'] is empty.

So the conclusion is json_decode($sJSONString, TRUE) is required if we use JSON string and then everything (including facets) will be working fine. Sorry for not carefully RTFM!

from elasticsearch-php.

polyfractal avatar polyfractal commented on May 17, 2024

Yep, you are correct. The client only accepts associative arrays in 99.99% of the APIs, so you have to convert it with json_decode() first. The only place that accepts a string for the body is the Bulk API.

That said, I agree that the client should throw an error in this particular case...it should have raised an exception saying that strings are not valid. I'll patch that up today. Thanks!

(And no worries about not reading the documentation...they are very sparse so far! A lot of work left to do)

from elasticsearch-php.

hellovic avatar hellovic commented on May 17, 2024

Cool, throwing an error should be helpful. Thanks and thanks for this nice PHP client.

from elasticsearch-php.

polyfractal avatar polyfractal commented on May 17, 2024

Heya @hellovic, I looked into this deeper and your first intuition (body could accept a JSON string) was correct: there is a bug in the Search endpoint. It was trying to stuff string bodies into the 'q' URI parameter, which is incorrect.

Thanks for the bug report, and sorry for the incorrect explanation...I really need to have a cup of coffee before responding to issues :)

from elasticsearch-php.

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.