Querying with elasticsearch and jcard json

88 views Asked by At

I have a data set containing vcards based on the JSON Jcard Mapping (https://www.rfc-editor.org/rfc/rfc7095) The problem is that I want to search on the 'fn' field only.

The vcard data has the following format.

["vcard",
     [
       ["version", {}, "text", "4.0"],
       ["fn", {}, "text", "John Doe"],
       ["gender", {}, "text", "M"],
       ["categories", {}, "text", "computers", "cameras"],
       ...
     ]
   ]

I'm creating a vcard document like this

> curl -X POST localhost:9200/vcards/id1 -d '{
     "id":"id1",
      "vcardArray" : ["vcard",
          [
            ["version", {}, "text", "4.0"],
            ["fn", {}, "text", "John Doe"],
            ["gender", {}, "text", "M"]
          ]
      ],
      "status":["registered"]
}'

Normally you would create a specific mapping so when the document is analysed a new index is created and searching for a fn field would look something like this....

curl -v -X POST  http://localhost:9200/vcards/_search -d '{ "query" :
       { "bool" : { "must": { "match" : {  
           "vcardArray.vcard.fn" : 
             { "query" : "Rik Ribbers" , "type" : "phrase" } 
       } } } }
}'

A potential mapping would look like this, but this one is not working

> curl -X PUT http://localhost:9200/vcards -d '
{
    "mappings": {
            "vcardArray" : {
                "type" : "nested",
                "properties" : {
                    "vcard" : {
                        "type" : "index",
                        "index" : "not_analyzed"
                    }
                }
            }
    }
}'

Any pointer to the correct mapping or query would be helpful.

0

There are 0 answers