Cool. For those who will come to this concern, here is a Gist which shows it: https://gist.github.com/dadoonet/7689977
--
David Pilato | Technical Advocate | Elasticsearch.com
@dadoonet | @elasticsearchfr
Le 28 novembre 2013 at 11:50:21, Quable - Sylvain Gourvil (sg@quable.fr) a écrit:
Thanks a lot !!
This works
curl -XGET 'localhost:9200/_search?pretty=true' -d '{
"query": {
"query_string": {
"query": "air",
"fields": [
"slug",
"name"
]
}
},
"facets": {
"marque2": {
"terms": {
"script": "_doc[\"marque\"].empty ? null : _source.marque"
}
},
"mime_type": {
"terms": {
"script": "_doc[\"mime_type\"].empty ? null : _source.mime_type"
}
},
"filetage": {
"terms": {
"script": "_doc[\"Filetage\"].empty ? null : _source.Filetage"
}
}
}
}’
But if « mime_type » has never been dynamically created in index, it fails.
So it is possible to facet on an existing field which is not not in results but it is not possible to filter on a field that does not exists.
I’ll manage with this for the moment.
Again, thank you David.
On 28 novembre 2013 at 11:31:56, David Pilato (david@pilato.fr) wrote:
Your understanding is correct. I was just hoping it to work
Try with this: "script": "doc['test'].empty ? null : _source.test"
--
David Pilato | Technical Advocate | Elasticsearch.com
@dadoonet | @elasticsearchfr
Le 28 novembre 2013 at 11:20:00, Quable - Sylvain Gourvil (sg@quable.fr) a écrit:
hi David,
Thanks for the quick answer.
This script :
curl -XGET 'localhost:9200/_search?pretty=true' -d '{
"query": {
"query_string": {
"query": "prof",
"fields": [
"slug",
"name"
]
}
},
"facets": {
"marque1": {
"terms": {
"field": "marque"
}
},
"marque2": {
"terms": {
"script": "_source.marque"
}
},
"mime_type": {
"terms": {
"script": "_source.mime_type !== undefined ? _source.mime_type : \"\""
}
}
}
}'
return
CompileException[[Error: not a statement, or badly formed structure]\n[Near : {... _source.mime_type !== undefined ? _source.mime_typ ....}]
Did I understood your answer ?
Hope to see you soon in ElasticSearch french meeting
Cordialement,
Sylvain Gourvil
Directeur Technique
Quable SAS - http://www.quable.fr
On 28 novembre 2013 at 11:11:49, David Pilato (david@pilato.fr) wrote:
Probably adding a if
statement in your script could help here?
"_source.mime_type !== undefined? _source.mime_type : """
Does it work for you?
--
David Pilato | Technical Advocate | Elasticsearch.com
@dadoonet | @elasticsearchfr
Le 28 novembre 2013 at 10:42:10, Georges@Bibtol (sg@quable.fr) a écrit:
Hi all,
I have multiple documents indexed with dynamic templates.
So docs have differents structures (some are common, some are not)
I am trying to do a simple query with facets on source field (not_analyzed fields).
My issue is that if the field does not exists on all docs, the quey failed.
I am sure there is a simple answer but after hours, I could not find the clue.
curl -XGET 'localhost:9200/_search?pretty=true' -d '{
"query": {
"query_string": {
"query": "prof",
"fields": [
"slug",
"name"
]
}
},
"facets": {
"marque1": {
"terms": {
"field": "marque"
}
},
"marque2": {
"terms": {
"script": "_source.marque"
}
},
"mime": {
"terms": {
"script": "_source.mime_type"
}
}
}
}'
Here, the 1st facet is ok but tokenized
The 2nd is OK and not tokenized. I'll take it)
The 3rd should be ok but mime_type is not stored for every documents so I have this error :
{
...
"failures" : [ {
"shard" : 0,
"status" : 500,
"reason" : "QueryPhaseExecutionException[[xxx][0]: query[(slug:prof | name:prof)],from[0],size[10]: Query Failed [Failed to execute main query]]; nested: PropertyAccessException[[Error: could not access: mime_type; in class: org.elasticsearch.search.lookup.SourceLookup]\n[Near : {... _source.mime_type ....}]\n ^\n[Line: 1, Column: 1]]; "
} ]
},
Could anyone help me on this ?
Thanks
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.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/etPan.52971fe8.643c9869.22e%40GeorgesAbitbol.local.
For more options, visit https://groups.google.com/groups/opt_out.
--
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.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/etPan.5297205f.3f6ab60f.3e14%40MacBook-Air-de-David.local.
For more options, visit https://groups.google.com/groups/opt_out.