ES 2.0 problem using PHP cURL commands


#1

Hello, I have been able to use the following test script without any problems using ElasticSearch v1.x. But now that I have updated to ElasticSearch 2.1 it no longer works. I know the index is correct as I have another application that works fine, but this basic cURL is not.

<?php

$data_string = '{
"from" : 0, "size" : 100,
"sort" : [
    { "date" : {"order" : "desc"} }
],
"query": {
        "match" : {
            "thread.title" : {
                "query" : "pictures"
            }
        }
    }
}';

$ch = curl_init('http://localhost:9200/xenforo150/_search?pretty=true');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);

curl_setopt($ch, CURLOPT_HTTPHEADER, array(                                                                          
'Content-Type: application/json',                                                                                
'Content-Length: ' . strlen($data_string))                                                                       
); 
 
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string );
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');

$result = curl_exec($ch);

echo $result;

#2

The output of $result is:

{
  "took" : 3,
  "timed_out" : false,
  "_shards" : {
    "total" : 5,
    "successful" : 5,
    "failed" : 0
  },
  "hits" : {
    "total" : 0,
    "max_score" : null,
    "hits" : [ ]
  }
}

(David Pilato) #3

I can't really see what is wrong here...

Can you give what is the output of GET xenforo150/_search?


#4

The following command executed from the terminal works properly:

curl -XGET 'http://localhost:9200/xenforo150/_search?q=title:pictures'

I get the the data I'm expecting to get in post number 1.


#5

I changed the script by removing the thread.title to just title and now the script works.


#6

This is the mapping, why can't I use thread.title as I was able to with ElasticSearch v1.x.

[root@ss0084 ~]# curl -XGET 'http://localhost:9200/xenforo150/_mapping?pretty=true'
{
  "xenforo150" : {
    "mappings" : {
      "post" : {
        "properties" : {
          "date" : {
            "type" : "long"
          },
          "discussion_id" : {
            "type" : "long"
          },
          "message" : {
            "type" : "string"
          },
          "node" : {
            "type" : "long"
          },
          "thread" : {
            "type" : "long"
          },
          "title" : {
            "type" : "string"
          },
          "user" : {
            "type" : "long"
          }
        }
      },
      "thread" : {
        "properties" : {
          "date" : {
            "type" : "long"
          },
          "discussion_id" : {
            "type" : "long"
          },
          "message" : {
            "type" : "string"
          },
          "node" : {
            "type" : "long"
          },
          "thread" : {
            "type" : "long"
          },
          "title" : {
            "type" : "string"
          },
          "user" : {
            "type" : "long"
          }
        }
      }
    }
  }
}

(David Pilato) #7

Read this: https://www.elastic.co/guide/en/elasticsearch/reference/current/breaking_20_mapping_changes.html#_type_name_prefix_removed


#8

Thank you, dadoonet.


(system) #9