Elasticsearch:查询数组元素

时间:2014-08-07 06:09:10

标签: elasticsearch

如何创建查询以搜索"电视天线"在Elasticsearch中只会返回第一个对象吗?

{
    "name": "First",
    "categories": ["Medium TV antennas and cables", "TV cables"]
},
{
    "name": "Second",
    "categories": ["antennas and cables", "TV and accessories"]
}

有人可以帮忙吗?

2 个答案:

答案 0 :(得分:1)

试试这个:

curl -XGET 'localhost:9200/indexxx/topic/_search?pretty=true' -d '{
  "query": {
    "match": {
      "categories": {
        "query": "TV antenna",
        "operator": "and"
      }
    }
  }
}'

答案 1 :(得分:0)

使用词组匹配查询:

{
    "query": {
        "match_phrase": {
            "categories": {
                "query": "TV antennas"
            }
        }
    }
}

http://www.elasticsearch.org/guide/en/elasticsearch/guide/current/phrase-matching.html