[英]Using elasticsearch wildcard with tire
I have a model with mapping 我有一个带有映射的模型
included do
tire.settings ElasticSearchAnalysis do
mapping _all: {enabled: false } do
indexes :postal_name, type: "string", index: :not_analyzed
# ...
end
end
end
I can do 我可以
curl http://localhost:9200/cities/_search?pretty -d '{ "query": { "wildcard": { "postal_name": "F?" } } }'
and get expected results of models in the state of Florida. 并获得佛罗里达州模型的预期结果。 But if I do
但是如果我这样做
City.search { query { string "wildcard:{postal_name:F?}" } }
elasticsearch returns a parse error saying it cannot parse the query: elasticsearch返回一个解析错误,表明它无法解析查询:
Parse Failure [Failed to parse source [{\n \"query\":{\n \"query_string\":{\n \"query\":\"wildcard:{postal_name:'F?'}\"\n }\n },\n \"size\":10\n}\n]]]; nested: QueryParsingException[[development_cities] Failed to parse query [wildcard:{postal_name:'F?'}]]; nested: ParseException[Cannot parse 'wildcard:{postal_name:'F?'}': Encountered \" \"}\" \"} \"\" at line 1, column 26.\nWas expecting one of:\n \"TO\" ...\n <RANGE_QUOTED> ...\n <RANGE_GOOP> ...\n ]
What is the proper way to pass in an arbitrary json to query for methods not supported by tire. 传递任意json以查询Tire不支持的方法的正确方法是什么?
You can access the query object to set up a wildcard query. 您可以访问查询对象以设置通配符查询。 It doesn't look like tire supports wildcard directly (or at least not that I could find):
它看起来不像Tyre直接支持通配符(或者至少不是我能找到的通配符):
City.search do
query do |q|
q.value = { wildcard: { postal_name: 'F?' } }
end
end
Generates a request like this: 生成这样的请求:
curl http://localhost:9200/cities/_search?pretty -d '{"query":{"wildcard":{"postal_name":"B?"}},"size":10}'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.