Can we add JSON to elasticsearch

186 views
Skip to first unread message

sohail ahmed

unread,
Mar 16, 2013, 1:30:50 AM3/16/13
to elastica-...@googlegroups.com
I am trying this code without success. But after json_decode($row, true); it's work then. Because it is now an array after json_decode();

Note: I want to add json without decode.


$elasticaIndex = $elasticaClient->getIndex('twitter_json');
$elasticaType = $elasticaIndex->getType('tweet_json');

$filename = dirname(__FILE__) . "/twitter.txt";

$fh = fopen($filename, 'r');
$counter = 0;

$documents = array();
while (( $row = fgets($fh)) != false ) {

$jsonTweet = $row;
if ( $jsonTweet == null)
continue;
$documents[] = new \Elastica\Document(uniqid(),$jsonTweet);
$counter++;
if($counter == 500)
break;
}

$elasticaType->addDocuments($documents);
$elasticaType->getIndex()->refresh();

ruflin

unread,
Mar 16, 2013, 6:28:36 PM3/16/13
to elastica-...@googlegroups.com
Interesting. I never had this case so far. So what you want is to add the "raw" json string to the Elastica_Document but then have it in elasticsearch as a document. Right?

The problem at the moment is, that Elastica is doing the whole json conversion automatically. So if you add a raw string, it encodes it a second time. We would have to introduce a special param to allow this. Feel free to open a pull request for this.

sohail ahmed

unread,
Mar 18, 2013, 12:38:19 AM3/18/13
to elastica-...@googlegroups.com
Thanks for reply ruflin. Yes I want to add "raw" json string. Can I will be able to search in that "raw" document after indexed.
1 more question cruntaly I add tweet Array with  json_decode($row, true); from above code. Elasticsearch map it automatically, Great. Now I want to search in spacific field. This time there are so many fields but I want to search in "Screen_name" field. What I have to do for it. I used term but without success.
Thanks again.

Shamin Mikhail

unread,
Mar 18, 2013, 3:20:26 PM3/18/13
to elastica-...@googlegroups.com
I've made a PR that fixes issue with raw data in bulk request: https://github.com/ruflin/Elastica/pull/352 , if it solves the problem i will merge it to master.

sohail ahmed

unread,
Mar 21, 2013, 7:22:42 AM3/21/13
to elastica-...@googlegroups.com
Thanks. Yes merger it to master please

ruflin

unread,
Mar 21, 2013, 9:54:40 AM3/21/13
to elastica-...@googlegroups.com
It is already merged ...

sohail ahmed

unread,
Mar 22, 2013, 12:04:28 AM3/22/13
to elastica-...@googlegroups.com
good thanks


On Thu, Mar 21, 2013 at 6:54 PM, ruflin <ruf...@gmail.com> wrote:
It is already merged ...

--
You received this message because you are subscribed to a topic in the Google Groups "Elastica - Elasticsearch PHP Client" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/elastica-php-client/h6-zw4TOHE4/unsubscribe?hl=en.
To unsubscribe from this group and all its topics, send an email to elastica-php-cl...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Reply all
Reply to author
Forward
0 new messages