# Elasticsearch search result problem

**URL:** <https://discuss.elastic.co/t/elasticsearch-search-result-problem/22082>\
**Category:** Elasticsearch\
**Created:** [February 11, 2015, 4:09am UTC](https://discuss.elastic.co/t/elasticsearch-search-result-problem/22082 "2015-02-11T04:09:13Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Veli\_Can\_TEFON](https://avatars.discourse-cdn.com/v4/letter/v/74df32/32.png) [@Veli\_Can\_TEFON](https://discuss.elastic.co/u/Veli_Can_TEFON)\
**Post date:** [February 11, 2015, 4:09am UTC](https://discuss.elastic.co/t/elasticsearch-search-result-problem/22082/1 "2015-02-11T04:09:13Z")

</div>

Hello,

I add data add Elasticsearch this code :

```
$data = array("name"=>HelperMC::strToUtf8(trim($name)),
        "urlname"=>HelperURL::strToURL(trim($name)),
        "price"=>number_format(HelperParser::clearTextFromPrice($price), 

```

2, ',', '.'),  
"price\_for\_filter"=\>HelperParser::clearTextFromPrice($price),  
"image"=\>$imgname,  
"description"=\>HelperMC::strToUtf8($description),  
"keywords"=\>HelperMC::strToUtf8($keywords),  
"url"=\>$k['url'],  
"sitemap\_id"=\>intval($sitemapId),  
"shop\_id"=\>$shop['shop\_id'],  
"logo"=\>$shop['logo'],  
"key"=\>$hashKey,  
"type"=\>intval(1),  
"shop\_rating\_count"=\>intval($shop['rating\_count']),  
"shop\_rating\_point"=\>intval($shop['rating\_point']),  
"created\_at"=\>date("Y-m-d H:i:s"),  
"updated\_at"=\>date("Y-m-d H:i:s"));

```
//create elasticsearch index
HelperES::insertEntry(json_encode($data),$hashKey);     

```

My insertEntry Function:

```
private static $elasticBase = "http://localhost:9200/shopping/items";

public static function insertEntry($data_string,$id = false){
    if($id)
        $url = self::$elasticBase."/".$id;
    else
        $url = self::$elasticBase;

    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL , $url);
    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");  
    curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string); 
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
    @$result = curl_exec($ch);
    curl_close($ch);

    return $result;
}

```

and my search Function :

```
public static function search($keyword, $defaultOperator = "OR" ,$start 

```

= 0, $size = 25, $from = 0, $to = 10000, $shopsArr = array(),$orderBy =  
"price", $order = "asc"){  
$searchUrl = self::$elasticBase."/\_search";

```
    if(count($shopsArr) > 0){
        $query = '{
                        "from" : '.$start.', "size" : '.$size.',
                        "query" : {
                            "filtered" : {
                             "query": {
                                "query_string": { "query": "'.$keyword.

```

'",  
"fields": ["name","urlname"],  
"default\_operator": "'.$defaultOperator.  
'"  
}  
},  
"filter" : {  
"bool" : {  
"must" : {  
"terms" : { "sitemap\_id" : '  
.json\_encode($shopsArr).' }  
},  
"must" : {  
"range" : {

"price\_for\_filter" : {  
"from" : "'.  
$from.'",  
"to" : "'.  
$to.'"  
}  
}  
}  
}  
}  
}  
},  
"sort" : [  
{"'.$orderBy.'" : {"order" : "'.$order  
.'", "mode" : "avg"}}  
]  
}';  
}else{  
$query = '{  
"from" : '.$start.', "size" : '.$size.',  
"query" : {  
"filtered" : {  
"query": {  
"query\_string": {  
"query": "'.$keyword.'",  
"fields": ["name","urlname"],  
"default\_operator": "'.$defaultOperator.  
'"  
}  
},  
"filter" : {  
"range" : {  
"price\_for\_filter" : {  
"from" : "'.$from.'",  
"to" : "'.$to.'"  
}  
}  
}  
}  
},  
"sort" : [  
{"'.$orderBy.'" : {"order" : "'.$order.'",  
"mode" : "avg"}}  
]  
}';  
}

```
    echo $query;    

    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL , $searchUrl);
    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");  
    curl_setopt($ch, CURLOPT_POSTFIELDS, $query); 
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
    @$result = curl_exec($ch);
    curl_close($ch);
    return $result;
}

```

But my search results not working.

Example : [http://goo.gl/KHO1Ia](http://goo.gl/KHO1Ia)

working but,

[http://goo.gl/GB8uUV](http://goo.gl/GB8uUV)

not working.

Pls help me? Thank you

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/4ad7004b-e867-41ac-9c30-a2c781735865%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/4ad7004b-e867-41ac-9c30-a2c781735865%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![Veli\_Can\_TEFON](https://avatars.discourse-cdn.com/v4/letter/v/74df32/32.png) [@Veli\_Can\_TEFON](https://discuss.elastic.co/u/Veli_Can_TEFON)\
**Post date:** [February 11, 2015, 2:46pm UTC](https://discuss.elastic.co/t/elasticsearch-search-result-problem/22082/2 "2015-02-11T14:46:01Z")

</div>

i think problem price\_for\_filter but working this -\> [http://goo.gl/AuxCrR](http://goo.gl/AuxCrR)

11 Şubat 2015 Çarşamba 06:09:13 UTC+2 tarihinde Veli Can TEFON yazdı:

> Hello,
> 
> I add data add Elasticsearch this code :
> 
> ```
> $data = array("name"=>HelperMC::strToUtf8(trim($name)),
> "urlname"=>HelperURL::strToURL(trim($name)),
> "price"=>number_format(HelperParser::clearTextFromPrice($price
> 
> ```
> 
> ), 2, ',', '.'),  
> "price\_for\_filter"=\>HelperParser::clearTextFromPrice($price),  
> "image"=\>$imgname,  
> "description"=\>HelperMC::strToUtf8($description),  
> "keywords"=\>HelperMC::strToUtf8($keywords),  
> "url"=\>$k['url'],  
> "sitemap\_id"=\>intval($sitemapId),  
> "shop\_id"=\>$shop['shop\_id'],  
> "logo"=\>$shop['logo'],  
> "key"=\>$hashKey,  
> "type"=\>intval(1),  
> "shop\_rating\_count"=\>intval($shop['rating\_count']),  
> "shop\_rating\_point"=\>intval($shop['rating\_point']),  
> "created\_at"=\>date("Y-m-d H:i:s"),  
> "updated\_at"=\>date("Y-m-d H:i:s"));
> 
> ```
> //create elasticsearch index
> HelperES::insertEntry(json_encode($data),$hashKey);     
> 
> ```
> 
> My insertEntry Function:
> 
> ```
> private static $elasticBase = "http://localhost:9200/shopping/items";
> 
> public static function insertEntry($data_string,$id = false){
> if($id)
> $url = self::$elasticBase."/".$id;
> else
> $url = self::$elasticBase;
> 
> $ch = curl_init();
> curl_setopt($ch, CURLOPT_URL , $url);
> curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");  
> curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string); 
> curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
> curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
> curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
> @$result = curl_exec($ch);
> curl_close($ch);
> 
> return $result;
> }
> 
> ```
> 
> and my search Function :
> 
> ```
> public static function search($keyword, $defaultOperator = "OR" ,$start 
> 
> ```
> 
> = 0, $size = 25, $from = 0, $to = 10000, $shopsArr = array(),$orderBy =  
> "price", $order = "asc"){  
> $searchUrl = self::$elasticBase."/\_search";
> 
> ```
> if(count($shopsArr) > 0){
> $query = '{
> "from" : '.$start.', "size" : '.$size.',
> "query" : {
> "filtered" : {
> "query": {
> "query_string": { "query": "'.$keyword
> 
> ```
> 
> .'",  
> "fields": ["name","urlname"],  
> "default\_operator": "'.  
> $defaultOperator.'"  
> }  
> },  
> "filter" : {  
> "bool" : {  
> "must" : {  
> "terms" : { "sitemap\_id" :  
> '.json\_encode($shopsArr).' }  
> },  
> "must" : {  
> "range" : {
> 
> "price\_for\_filter" : {  
> "from" : "'  
> .$from.'",  
> "to" : "'  
> .$to.'"  
> }  
> }  
> }  
> }  
> }  
> }  
> },  
> "sort" : [  
> {"'.$orderBy.'" : {"order" : "'.  
> $order.'", "mode" : "avg"}}  
> ]  
> }';  
> }else{  
> $query = '{  
> "from" : '.$start.', "size" : '.$size.',  
> "query" : {  
> "filtered" : {  
> "query": {  
> "query\_string": {  
> "query": "'.$keyword.'",  
> "fields": ["name","urlname"],  
> "default\_operator": "'.  
> $defaultOperator.'"  
> }  
> },  
> "filter" : {  
> "range" : {  
> "price\_for\_filter" : {  
> "from" : "'.$from.'",  
> "to" : "'.$to.'"  
> }  
> }  
> }  
> }  
> },  
> "sort" : [  
> {"'.$orderBy.'" : {"order" : "'.$order.'",  
> "mode" : "avg"}}  
> ]  
> }';  
> }
> 
> ```
> echo $query;    
> 
> $ch = curl_init();
> curl_setopt($ch, CURLOPT_URL , $searchUrl
> 
> ```
> 
> ...

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/19d92ca9-f88f-4387-adc9-3c35065496d1%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/19d92ca9-f88f-4387-adc9-3c35065496d1%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 6, 2017, 12:33am UTC](https://discuss.elastic.co/t/elasticsearch-search-result-problem/22082/3 "2017-07-06T00:33:30Z")

</div>


