[英]How to specify certain fields only in the query property
I am using a service which wraps requests to Elastic Search. 我正在使用一个服务,它将请求包装到Elastic Search。 This service only allows me to send the query
property to Elastic Search. 此服务仅允许我将query
属性发送到Elastic Search。 I want to tell Elastic Search to look only for matches in a certain field in a document. 我想告诉Elastic Search只查找文档中某个字段的匹配项。
For example, if this is my document: 例如,如果这是我的文档:
{
name: 'foo',
value: 'true'
}
Then I want to tell Elastic Search to look only for documents where name
equals foo
. 然后我想告诉Elastic Search只查找name
等于foo
文档。
The Elastic Search documentation says to do this by using the fields
property like so: Elastic Search 文档说通过使用fields
属性来执行此操作:
{
"multi_match" : {
"query" : "this is a test",
"fields" : [ "subject^3", "message" ]
}
}
But I can ONLY access the query
property, so I can't specify fields
. 但我只能访问query
属性,所以我不能指定fields
。 Lower down on the page, under best fields it says that this is equivalent to doing something like +first_name:will +first_name:smith
. 在页面下方,在最佳字段下,它表示这相当于执行类似+first_name:will +first_name:smith
。 But when I put this, it's looking for text that actually matches +first_name:will +first_name:smith
in the value, rather than looking for a first_name
field that has a value will
. 但是,当我把这个,它是寻找实际匹配的文本+first_name:will +first_name:smith
的价值,而不是寻找一个first_name
具有值字段will
。
Is it possible to specify what field to search in with Elastic Search using only the query
property? 是否可以仅使用query
属性指定要使用弹性搜索搜索的字段?
This sounds like a perfect match for query_string
( https://www.elastic.co/guide/en/elasticsearch/reference/1.x/query-dsl-query-string-query.html ). 这听起来像是query_string
的完美匹配( https://www.elastic.co/guide/en/elasticsearch/reference/1.x/query-dsl-query-string-query.html )。 You can do something like this with it: 你可以用它做这样的事情:
"query_string" : {
"query" : "subject:whatever OR message:whatever"
}
So, if you can change multi_match
to query_string
this would be what you are looking for. 所以,如果你可以改变multi_match
到query_string
这将是你在找什么。
Lucene supports fielded data. Lucene支持现场数据。 When performing a search you can either specify a field, or use the default field. 执行搜索时,您可以指定字段,也可以使用默认字段。 The field names and default field is implementation specific. 字段名称和默认字段是特定于实现的。
You can search any field by typing the field name followed by a colon ":" and then the term you are looking for. 您可以通过键入字段名称后跟冒号“:”来搜索任何字段,然后输入您要查找的术语。
{
"query": {
"query_string": {
"query": "Name:\"foo bar cook\"",
"default_operator" : "or"
}
}
}
use default_operator
and to perform AND operation, or to perform OR kind of operation among the values 使用default_operator
并执行AND操作,或在值之间执行OR类操作
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.