2016-08-08 3 views
0

내 대답은 내가 각 hits.hits 요소에서 제거 할 _index, _type 및 _score 필드를 원하는이제거 메타 데이터 검색 API에서

{ 
    "took":88, 
    "timed_out":false, 
    "_shards":{ 
     "total":3, 
     "successful":3, 
     "failed":0 
    }, 
    "hits":{ 
     "total":2, 
     "max_score":1.0, 
     "hits":[ 
      { 
       "_index":"myindex", 
       "_type":"mytype", 
       "_id":"first", 
       "_score":1.0, 
       "fields":{ 
        "name":[ "John Smith" ] 
       } 
      }, 
      { 
       "_index":"myindex", 
       "_type":"mytype", 
       "_id":"second", 
       "_score":1.0, 
       "fields":{ 
        "name":[ "John Doe" ] 
       } 
      } 
     ] 
    } 
} 

처럼 보인다 hits.hits. 어떻게해야합니까?

+0

검색어를 어떻게 보내십니까? – Val

+0

@Val : 검색 API (POST) – musicsquad

답변

2

당신은이 같은 쿼리 문자열에 filter_path 매개 변수를 지정하여 response filtering를 사용할 수 있습니다

curl -XPOST 'localhost:9200/_search?pretty&fields=name&filter_path=hits.hits.fields' -d '{ 
    "query": { 
     "match": { 
      "name": "john" 
     } 
    } 
}' 

또는 소스 필터링을 사용하는 대신

curl -XPOST 'localhost:9200/_search?pretty&_source=name&filter_path=hits.hits._source' -d '{ 
    "query": { 
     "match": { 
      "name": "john" 
     } 
    } 
}' 

귀하의 응답이 대신에 다음과 같이 표시됩니다

{ 
    "hits":{ 
     "hits":[ 
      { 
       "fields":{ 
        "name":[ "John Smith" ] 
       } 
      }, 
      { 
       "fields":{ 
        "name":[ "John Doe" ] 
       } 
      } 
     ] 
    } 
} 
+0

검색 API (POST) – musicsquad

+0

에 대한이 작동하지 않습니다 물론 시도해보십시오. – Val

+0

아니요, 요청 URL은 POST http : // /myindex/mytype/_search?filterPath=hits.hits.fields&fields=name과 비슷하지만 각 조회 요소에는 여전히 _index, _type 및 _score가 있습니다. btw, "name"이 자동으로 문자열 배열이되는 이유는 무엇입니까? – musicsquad

관련 문제