Using wildcards in query_string fields


(ltuhuru) #1

I'm a new user, so hopefully this is something really simple. I have two "message" objects in my index, "typeA" and "typeB", each of which has a "net" field. I'd like to be able to search for all objects whose net fields match a pattern.

If I specify the fields explicitly, the query returns the appropriate docs. If I use a wildcard in the fields for the query_string, the query returns no hits. Clearly I don't understand something - can anyone point out what I'm missing?

curl -XPUT localhost:9200/nettest/message/typeA-1 -d '{
"typeA" : {
"net" : "NET11_TEST"
}
}'

curl -XPUT localhost:9200/nettest/message/typeB-1 -d '{
"typeB" : {
"net" : "NET01_TEST"
}
}'

This query returns both docs:
curl -XGET localhost:9200/nettest/_search?pretty=true -d '{
"query" : {
"query_string" : {
"fields" : ["message.typeA.net", "message.typeB.net"],
"query" : "NET*"
}
}
}'

This query returns no docs:
curl -XGET localhost:9200/nettest/_search?pretty=true -d '{
"query" : {
"query_string" : {
"fields" : ["message..net"],
"query" : "NET
"
}
}
}'


(ltuhuru) #2

Found my problem. Get rid of the leading type "message" in the field path and wildcards in the fields work.

curl -XGET localhost:9200/nettest/_search?pretty -d '{
"query" : {
"query_string" : {
"fields" : [".ne"],
"query" : "NET*"
}
}
}'


(system) #3